#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> labyrinth_jerry;
vector<vector<int>> labyrinth_tom;
vector<int> bfs (int from, int to, vector<vector<int>> &labyrinth) {
queue<vector<int>> q; // first: node, second: depth;
vector<bool> been_here(labyrinth.size(), false);
vector<int> path;
q.push({from, 0, -1});
while(!q.empty()) {
if (q.front()[0] == to) {
path.push_back(q.front()[0]);
return path;
}
for (int i = 0; i < labyrinth[q.front()[0]].size(); i++) {
if(been_here[labyrinth[q.front()[0]][i]]) continue;
q.push({labyrinth[q.front()[0]][i], q.front()[1]+1, q.front()[0]});
been_here[labyrinth[q.front()[0]][i]] = true;
}
if (path.empty() || q.front()[2] == path[path.size() -1]) path.push_back(q.front()[0]);
q.pop();
}
return path;
}
int main() {
int point_count, road_count, tom_pos, tries_count, hole_pos;
cin >> point_count >> road_count >> tom_pos >> tries_count >> hole_pos;
labyrinth_jerry.assign(road_count, vector(0, 0));
labyrinth_tom.assign(road_count, vector(0, 0));
for (int i = 0; i < road_count; i++) {
int road_from, road_to, width;
cin >> road_from >> road_to >> width;
if (width == 2) {
labyrinth_jerry[road_from].push_back(road_to);
labyrinth_jerry[road_to].push_back(road_from);
labyrinth_tom[road_from].push_back(road_to);
labyrinth_tom[road_to].push_back(road_from);
} else {
labyrinth_jerry[road_from].push_back(road_to);
labyrinth_jerry[road_to].push_back(road_from);
}
}
vector<int> tries(tries_count, 0);
for (int i = 0; i < tries_count; i++) {
cin >> tries[i];
}
vector<int> tom_path = bfs(tom_pos, hole_pos, labyrinth_tom);
/*for (int i = 0; i < tom_path.size(); i++) {
cout << tom_path[i] << " ";
}
cout << endl;*/
for (int j = 0; j < tries.size(); j++) {
vector<int> jerry_path = bfs(tries[j], hole_pos, labyrinth_jerry);
/*for (int i = 0; i < jerry_path.size(); i++) {
cout << jerry_path[i] << " ";
}
cout << endl;*/
bool should = false;
for (int i = 0; i < jerry_path.size(); i++) {
if (tom_path[i] == jerry_path[i+1]) {
cout << "NEM" << endl;
should = true;
break;
}
}
if (should) {
continue;
} else cout << "IGEN" << endl;
}
return 0;
}