#include #include #include #define ll long long using namespace std; template void read(T &x) { x = 0; char c = getchar(); int f = 0; for (; !isdigit(c); c = getchar()) f |= c == '-'; for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ '0'); if (f) x = -x; } template void write(T x, char ed = '\n') { if (x < 0) putchar('-'), x = -x; static short st[30], tp; do st[++tp] = x % 10, x /= 10; while (x); while (tp) putchar(st[tp--] | '0'); putchar(ed); } int T, n, rt, ed[55][55], vis[55]; int main() { for (read(T); T; --T) { read(n); for (int i = 1, v;i <= n; ++i) read(v), v ? rt = i : 0; for (int i = 1;i <= n; ++i) for (int j = 1;j <= n; ++j) read(ed[i][j]); int nw = rt; memset(vis, 0, sizeof(vis)); for (int i = 1;i < n - 1; ++i) { for (int j = 1;j <= n; ++j) if (!vis[ed[nw][j]]) { vis[ed[nw][j]] = 1, nw = ed[nw][j]; break; } } puts(vis[rt] ? "lieren" : "langren"); } return 0; }