#include typedef long long LL; #define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; ++i) #define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; --i) template void in(Tp &x) { char ch = getchar(), f = 1; x = 0; while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar(); if (ch == '-') f = -1, ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); x *= f; } template bool chkmax(Tp &x, Tp y) {return x >= y ? 0 : (x=y, 1);} template bool chkmin(Tp &x, Tp y) {return x <= y ? 0 : (x=y, 1);} template Tp Max(const Tp &x, const Tp &y) {return x > y ? x : y;} template Tp Min(const Tp &x, const Tp &y) {return x < y ? x : y;} const int MAXN = 110; int T, p[MAXN][MAXN]; char is[MAXN]; void solve() { int n; in(n); int lr = 0; FOR(i, 1, n) { is[i] = true; int x; in(x); if (x) lr = i; } FOR(i, 1, n) FOR(j, 1, n) in(p[i][j]); int now = lr; FOR(i, 1, n - 2) { FOR(j, 1, n) if (is[p[now][j]] && (i == 1 || p[now][j] != now)) { int nxt = p[now][j]; if (nxt == lr) {puts("lieren"); return;} is[nxt] = false; now = nxt; // printf("%d ", nxt); break; } } puts("langren"); } int main() { in(T); while (T--) solve(); return 0; }