```#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <cassert>
#include <string.h>

#include <time.h>
#include <random>
#include <iomanip>
using namespace std;

#define ll long long
#define N 255
#define M 100005

ll M1, N1, K1, M2, N2, K2;

vector<vector<ll> > g1[N];
map<ll, ll> g2[N];    // map[op, dest]

vector<vector<ll> > f2[N];
map<ll, ll> f1[N];    // map[op, dest]

bool edges1[M];
bool node1[N];

bool dfs(ll u, vector<vector<ll> > g[N], vector<bool> &seen, bool edges[N]) {
if (seen[u])
return u==(N1-1);
seen[u] = true;
bool canReachEndNode = false;
for (ll i = 0; i < g[u].size(); i++) {
ll cur = g[u][i][0];
if (dfs(cur, g, seen, edges)) {
canReachEndNode = true;
}
}
node1[u] |=  canReachEndNode || (u==N1-1);
return node1[u];
}

bool dfs2(ll u1, ll u2, vector<vector<ll> > gg1[N], map<ll, ll> gg2[N], vector<bool> &ss1) {
if (ss1[u1])
return true;
ss1[u1] = true;

bool isGood = true;
for (ll i = 0; i < gg1[u1].size(); i++) {
if (!edges1[gg1[u1][i][2]])
continue;

ll op = gg1[u1][i][1];
ll dest = gg1[u1][i][0];
if (gg2[u2].find(op) == gg2[u2].end())
return false;
if (dest == N1-1 && gg2[u2][op] != N2-1)
return false;
isGood = isGood && dfs2(dest, gg2[u2][op], gg1, gg2, ss1);
}
return isGood;
}

bool solve2() {
vector<bool> seen(N1, false);
dfs(0, g1, seen, edges1);

for (ll i = 0; i < N1; i++) {
for (ll j = 0; j < g1[i].size(); j++) {
ll dest = g1[i][j][0];
if (node1[dest])
edges1[g1[i][j][2]] = true;
}
}

vector<bool> ss1(N1, false);
bool good = dfs2(0, 0, g1, g2, ss1);

return good;
}

void solve() {
for (ll i = 0; i < N; i++) {
g1[i].clear();
f2[i].clear();
f1[i].clear();
g2[i].clear();
node1[i] = false;
}
for (ll i = 0; i < M; i++) {
edges1[i] = false;
}

cin >> M1 >> N1 >> K1 >> M2 >> N2 >> K2;
for (ll i = 0; i < M1; i++) {
ll Tin, Tout, S;
cin >> Tin >> Tout >> S;
g1[Tin].push_back({Tout,S,i});
f1[Tin][S] = Tout;
}
for (ll i = 0; i < M2; i++) {
ll Tin, Tout, S;
cin >> Tin >> Tout >> S;
g2[Tin][S] = Tout;
f2[Tin].push_back({Tout,S,i});
}

bool good1 = solve2();
for (ll i = 0; i < N; i++) {
g2[i] = f1[i];
g1[i] = f2[i];
node1[i] = false;
}
for (ll i = 0; i < M; i++) {
edges1[i] = false;
}
swap(N1, N2);
swap(M1, M2);
swap(K1, K1);
bool good2 = solve2();
if (good1&&good2)
cout << "eligible" << endl;
else
cout << "not eligible" << endl;
}

int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
ll t;
cin >> t;
for (ll i = 0; i < t; i++) {
solve();
}
}```