#include <iostream>
#include <algorithm>
#include <set>
#include <queue>
#include <vector>
#include <cstring>

using namespace std;
typedef pair<int, int> pii;
const int N = 256;

void print(const vector<vector<pii>> &dfa) {
	cerr << "begin dfa with " << dfa.size() << " states" << endl;
	for (int i = 0; i < dfa.size(); i++) {
		cerr << i << ":";
		for (int j = 0; j < dfa[i].size(); j++) {
			cerr << " " << dfa[i][j].first << "->" << dfa[i][j].second;
		}
		cerr << endl;
	}
	cerr << endl;
}

vector<vector<pii>> revEdges(const vector<vector<pii>> &dfa) {
	int n = dfa.size();
	vector<vector<pii>> res(n, vector<pii>());
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < dfa[i].size(); j++) {
			pii z = dfa[i][j];
			res[z.second].push_back(pii(z.first, i));
		}
	}
	return res;
}

int repr[N], repr2[N];
bool visited[N], visited1[N], visited2[N], diff[N][N];
vector<vector<pii>> reduce(vector<vector<pii>> dfa) {
	int n = dfa.size();
	memset(repr, 0, sizeof repr);

	// bfs to erase nodes unreachable from start
	memset(visited, 0, sizeof visited);
	queue<int> q;
	q.push(0);
	while (!q.empty()) {
		int curr = q.front(); q.pop();
		if (visited[curr]) continue;
		visited[curr] = true;
		for (int i = 0; i < dfa[curr].size(); i++) {
			q.push(dfa[curr][i].second);
		}
	}
	for (int i = 0; i < n; i++) if (!visited[i]) repr[i] = -1;

	// bfs to erase nodes that cannot reach end
	int endNode = n-1;
	vector<vector<pii>> rev = revEdges(dfa);
	memset(visited, 0, sizeof visited);
	q.push(endNode);
	while (!q.empty()) {
		int curr = q.front(); q.pop();
		if (visited[curr]) continue;
		visited[curr] = true;
		for (int i = 0; i < rev[curr].size(); i++) {
			q.push(rev[curr][i].second);
		}
	}
	for (int i = 0; i < n; i++) if (!visited[i]) repr[i] = -1;
	if (repr[0] < 0 || repr[endNode] < 0) return vector<vector<pii>>();

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < dfa[i].size(); j++) {
			if (repr[dfa[i][j].second] < 0) {
				dfa[i].erase(dfa[i].begin()+j); j--;
			}
		}
	}

	// minimize dfa states
	// step 1: split into two partitions: {{rest}, {endNode}} and exclude useless nodes
	vector<vector<int>> parts;
	if (n == 1) {
		parts.resize(1);
		parts[0].push_back(0);
		repr[0] = 0;
	} else {
		parts.resize(2);
		for (int i = 0; i < n; i++) {
			if (repr[i] >= 0) {
				if (i != endNode) {
					repr[i] = 0;
					parts[0].push_back(i);
				} else {
					repr[i] = 1;
					parts[1].push_back(i);
				}
			}
		}
	}

	//cerr << "repr: "; for (int i = 0; i < n; i++) cerr << repr[i] << " "; cerr << endl;

	// step 2: while true, divide each set into distinct sets until end
	bool done = false;
	while (!done) {
		vector<vector<int>> nxt(parts.size(), vector<int>());
		for (int i = 0; i < n; i++) repr2[i] = repr[i];

		// for each set
		for (int i = 0; i < parts.size(); i++) {
			int j0 = parts[i][0];
			nxt[i].push_back(j0);
			repr2[j0] = i;
			if (parts[i].size() == 1) continue;

			// test if each pair is different
			// pair of nodes is different iff for some transition
			// they transition to nodes that are in different sets
			int nn = parts[i].size();
			for (int j = 0; j < nn; j++) {
				diff[j][j] = false;
				for (int k = j+1; k < nn; k++) {
					int jj = parts[i][j];
					int kk = parts[i][k];
					bool currDiff = false;
					if (dfa[jj].size() != dfa[kk].size()) currDiff = true;
					for (int z = 0; !currDiff && z < dfa[jj].size(); z++) {
						if (dfa[jj][z].first != dfa[kk][z].first ||
							repr[dfa[jj][z].second] != repr[dfa[kk][z].second]) {
							currDiff = true;
						}
					}
					diff[j][k] = diff[k][j] = currDiff;
				}
			}

			// separate into different sets
			for (int j = 1; j < nn; j++) {
				int jj = parts[i][j];
				int k = 0; while (k < j && diff[j][k]) k++;
				int z;
				if (k == j) {
					z = nxt.size();
					nxt.push_back(vector<int>());
				} else {
					z = repr2[parts[i][k]];
				}
				nxt[z].push_back(jj);
				repr2[jj] = z;
			}
		}

		done = true;
		parts = nxt;
		for (int i = 0; i < n; i++) {
			if (repr[i] != repr2[i]) done = false;
			repr[i] = repr2[i];
		}

		//cerr << "repr: "; for (int i = 0; i < n; i++) cerr << repr[i] << " "; cerr << endl;

	}

	//cerr << endl;

	// for each set, choose one representative and make that a node
	vector<vector<pii>> res(parts.size(), vector<pii>());
	for (int i = 0; i < parts.size(); i++) {
		int ii = parts[i][0];
		for (int j = 0; j < dfa[ii].size(); j++) {
			int c = dfa[ii][j].first;
			int dst = repr[dfa[ii][j].second];
			if (dst >= 0) {
				res[repr[ii]].push_back(pii(c, dst));
			}
		}
	}
	return res;
}

int map21[N];
bool equiv(const vector<vector<pii>> &dfa1, const vector<vector<pii>> &dfa2) {
	if (dfa1.size() != dfa2.size()) return false;
	if (dfa1.size() == 0) return true;

	// bfs to test if graph is completely equal
	memset(visited1, 0, sizeof visited1);
	memset(visited2, 0, sizeof visited2);

	queue<int> q1, q2;
	q1.push(0); q2.push(0);
	while (!q1.empty() && !q2.empty()) {
		int u1 = q1.front(); q1.pop();
		int u2 = q2.front(); q2.pop();

		if (visited1[u1]) continue;
		visited1[u1] = true;
		visited2[u2] = true;
		map21[u2] = u1;

		if (dfa1[u1].size() != dfa2[u2].size()) return false;

		for (int i = 0; i < dfa1[u1].size(); i++) {
			int c1 = dfa1[u1][i].first;
			int c2 = dfa2[u2][i].first;
			if (c1 != c2) return false;

			int v1 = dfa1[u1][i].second;
			int v2 = dfa2[u2][i].second;
			if (visited1[v1] != visited2[v2]) return false;
			if (visited1[v1] && map21[v2] != v1) return false;
			q1.push(v1); q2.push(v2);
		}
	}
	if (q1.empty() != q2.empty()) return false;
	return true;
}

bool seen1[N][N], seen2[N][N];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int ncase; cin >> ncase;
	for (int csnum = 1; csnum <= ncase; csnum++) {
		int m1, n1, k1, m2, n2, k2; cin >> m1 >> n1 >> k1 >> m2 >> n2 >> k2;
		vector<vector<pii>> adj1(n1, vector<pii>());
		vector<vector<pii>> adj2(n2, vector<pii>());
		memset(seen1, 0, sizeof seen1);
		memset(seen2, 0, sizeof seen2);
		for (int i = 0; i < m1; i++) {
			int tin, tout, s; cin >> tin >> tout >> s;
			if (!seen1[tin][s]) {
				adj1[tin].push_back(pii(s, tout));
				seen1[tin][s] = true;
			}
		}
		for (int i = 0; i < m2; i++) {
			int tin, tout, s; cin >> tin >> tout >> s;
			if (!seen2[tin][s]) {
				adj2[tin].push_back(pii(s, tout));
				seen2[tin][s] = true;
			}
		}
		for (int i = 0; i < n1; i++) sort(adj1[i].begin(), adj1[i].end());
		for (int i = 0; i < n2; i++) sort(adj2[i].begin(), adj2[i].end());

		//print(adj1); print(adj2);

		adj1 = reduce(adj1);
		adj2 = reduce(adj2);

		//print(adj1); print(adj2);

		if (equiv(adj1, adj2)) {
			cout << "eligible" << endl;
		} else {
			cout << "not eligible" << endl;
		}
	}
}