#include #define ls(p) (p << 1) #define rs(p) (p << 1 | 1) #define For(i,l,r) for (register int i=l; i<=r; i++) using namespace std; typedef unsigned long long LL; typedef signed long long ll; template inline void read(T &x) { char c = getchar(); int w = 1; x = 0; while (!isdigit(c)) (c == '-') && (w = -w), c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar(); x *= w; } const int N = 55; int T, n, w[N], a[N][N]; signed main() { read(T); while (T -- > 0) { read(n); for (register int i=1; i<=n; ++i) { read(w[i]); } int id; for (register int i=1; i<=n; ++i) { for (register int j=1; j<=n; ++j) { read(a[i][j]); } if (w[i]) { id = a[i][1]; } } if (w[id] == 1) { puts("lieren"); continue; } w[id] = -1; int now = n-1; while (true) { if (now <= 2) { puts("langren"); break; } for (register int i=1; i<=n; ++i) { if (~w[a[id][i]]) { id = a[id][i]; break; } } if (w[id] == 1) { puts("lieren"); break; } w[id] = -1; -- now; } } return 0; }