// Skyqwq #include #include #define pb push_back #define fi first #define se second #define mp make_pair using namespace std; typedef long long LL; template void chkMax(T &x, T y) { if (y > x) x = y; } template void chkMin(T &x, T y) { if (y < x) x = y; } template void inline read(T &x) { int f = 1; x = 0; char s = getchar(); while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); } while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar(); x *= f; } const int N = 55; int n, a[N], rk[N][N], rt; bool st[N]; void inline work() { int u = rk[rt][1]; int cnt = n; while (1) { --cnt; st[u] = 1; if (a[u] == 1) { puts("lieren"); return; } if (cnt <= 2) { puts("langren"); return; } for (int i = 1; i <= n; i++) { if (!st[rk[u][i]]) { u = rk[u][i]; break; } } } } int main() { int T; read(T); while (T--) { read(n); for (int i = 1; i <= n; i++) { read(a[i]); st[i] = 0; if (a[i]) rt = i; } for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) read(rk[i][j]); work(); } return 0; }