#pragma GCC optimize("O3") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ri register signed #define RI register signed #define cf cout.flush(); #define lson (rt<<1|1) #define rson (rt<<1) #define lson1 (rt1<<1) #define rson1 (rt1<<1|1) #define lson2 (rt2<<1) #define rson2 (rt2<<1|1) #define mid ((l+r)>>1) #define mid1 ((l1+r1)>>1) #define mid2 ((l2+r2)>>1) #define mes(x) memset(x,0,sizeof x) typedef long long LL; typedef long long ll; typedef unsigned long long ull; typedef pair pll; typedef pairP; typedef pair PP; typedef pair PPll; //#define int long long //#define double long double #define ri register signed #define il inline #define deb(...) logger(#__VA_ARGS__,__VA_ARGS__) template void logger(string vars, Args&&... values) { cout << vars << " = "; string delim = ""; //(..., (cout << delim << values, delim = ", ")); } inline string toString(int x) { string ans = ""; bool negtive = x < 0; x = abs(x); while (x)ans.push_back(x % 10 + '0'), x /= 10; if (ans.size() == 0)ans = "0"; if (negtive)ans.push_back('-'); for (int i = 0; i < ans.size() / 2; i++) swap(ans[i], ans[ans.size() - 1 - i]); return ans; } inline int toInt(const string&str) { int ans = 0; bool negtive = str[0] == '-'; for (int i = negtive; i < str.size(); i++) ans = ans * 10 + str[i] - '0'; if (negtive)ans *= -1; return ans; } inline int gcd(int x, int y) { return x ? gcd(y%x, x) : y; } ll exgcd(ll a, LL b, LL &x, LL &y) { LL d = a; if (b == 0) x = 1, y = 0; else { d = exgcd(b, a%b, y, x), y -= a / b * x; } return d; } const int mod = 998244353; inline int read() { int ans = 0; char last = ' ', ch = getchar(); while (!(ch >= '0' && ch <= '9'))last = ch, ch = getchar(); while (ch >= '0' && ch <= '9')ans = (ans << 3) + (ans << 1) + ch - '0', ch = getchar(); return ans; } inline int QPow(ll a, ll b) { LL ans = 1; if (b < 0)return 0; while (b) { if (b & 1)ans = ans * a; a = a * a; b >>= 1; } return ans; } inline int QPow(LL a, LL b, const int&mod) { LL ans = 1; while (b) { if (b & 1)ans = ans * a%mod; a = a * a%mod; b >>= 1; } return ans; } const double PI = 3.141592653589793115997963468544185161590576171875; const double e = 2.718281828459045; void ask(int x) { cout << '?' << ' ' << x << endl; cf; } void decide(int x) { cout << "! " << x << endl; cf; } short _min(short a, short b) { return a < b ? a : b; } const int inf = 1+(1 << 30); const int inf2 = 10000; const double eps = 1e-10; int db_cmp(double x, double y) { if (fabs(x - y) < eps)return 0; if (x > y)return 1; return -1; } double distance(P p1, P p2) { return sqrt((p1.first - p2.first)*(p1.first - p2.first) + (p2.second - p1.second)*(p2.second - p1.second)); } const int maxn = 1002; LL inv[maxn]; LL fac[maxn], fac_1[maxn]; LL QPow(LL a, LL b, LL md) { LL ans = 1; while (b) { if (b & 1)ans = ans * a%md; a = a * a%md; b >>= 1; } return ans; } void getInv() { inv[1] = 1; for (int i = 2; i < maxn; i++) inv[i] = (mod - mod / i)*inv[mod%i] % mod; } void init() { fac[0] = fac_1[0] = 1; for (int i = 1; i < maxn; i++) fac[i] = fac[i - 1] * i%mod, fac_1[i] = fac_1[i - 1] * inv[i] % mod; } LL C(int n, int m) { if (n < m || n < 0 || m < 0)return 0; return fac[n] * fac_1[n - m] % mod*fac_1[m] % mod; } int p[55][55]; bool dead[55]; /*#define N 101 struct matrix { int m[N][N]; }; matrix b, ans,cc,ans2; char str[101]; int len; inline matrix mul(matrix a, matrix b) { RI i, j, k; matrix c; for (i = 0; i < len; i++) for (j = 0; j < len; j++) { c.m[i][j] = 0; for (k = 0; k < len; k++) c.m[i][j] += (a.m[i][k] * b.m[k][j])%mod; c.m[i][j] %= mod; } return c; } inline matrix mul2(matrix a, matrix b) { RI i, j, k; matrix c; for (i = 0; i < len; i++) for (j = 0; j < len; j++) { c.m[i][j] = 0; for (k = 0; k < len; k++) c.m[i][j] += (a.m[i][k] * b.m[k][j]) % mod; c.m[i][j] %= mod; } return c; } void mpow(matrix ma, signed n) { RI i; memset(ans.m, 0, sizeof(ans.m)); for (i = 0; i < len; i++) ans.m[i][i] = 1; for (; n; n >>= 1) { if (n & 1) ans = mul(ans, ma); ma = mul(ma, ma); } } void mpow2(matrix ma,matrix mb, signed n) { RI i; memset(ans.m, 0, sizeof(ans.m)); for (i = 0; i < len; i++) ans.m[i][i] = 1; memset(ans2.m, 0, sizeof(ans.m)); for (i = 0; i < len; i++) ans2.m[i][i] = 1; for (; n; n >>= 1) { if (n & 1) ans = mul(ans, ma),ans2=mul2(ans,ma); ma = mul(ma, ma); mb = mul(mb, mb); } } bool mo[N][N]; int Max[maxn << 2];*/ signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //getInv(); //init(); signed t, n, k, m; /*cin >> t; while (t--) { cin >> n >> m>>k; len = n; int tot = 0; for (int i = 1; i <= m; i++) { int u, v, w; cin >> u >> v >> w; u--, v--; b.m[u][v] = b.m[v][u] = 1; mo[u][v] = w; } mpow(b, k); tot = ans.m[0][n-1]; mes(mo); }*/ //cin >> n; cin >> t; while (t--) { mes(dead); cin >> n; int wolf = 0; for (int i = 1; i <= n; i++) { int tmp; cin >> tmp; if (tmp == 1)wolf = i; } for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> p[i][j]; int cur = 0; int stillAlive = n-1; cur = p[wolf][1]; dead[cur] = 1; bool flag = 0; if (cur == wolf)flag = 1; while (stillAlive > 2 && !flag) { int id = 0, Min = 10000; for (int i = 1; i <= n; i++) { if (!dead[p[cur][i]]) { id = p[cur][i]; break; } } stillAlive--; dead[id] = 1; cur = id; if (id == wolf) flag = 1; } if (!flag) cout << "langren\n"; else cout << "lieren\n"; } //system("pause"); return 0; }