/* * Author: Kewth * Date: echo -n ' ' && date +%Y.%m.%d # Type "!!sh" in Vim. * Solution: To be updated after "Accept". * Digression: * CopyRight: __ __ __ __ | |/ |.-----.--.--.--.| |_| |--. | < | -__| | | || _| | |__|\__||_____|________||____|__|__| */ #include #include #define debug(...) fprintf(stderr, __VA_ARGS__) typedef long long ll; static struct { inline operator int () { int x; return scanf("%d", &x), x; } /* inline operator ll () { ll x; return scanf("%lld", &x), x; } */ template inline void operator () (T &x) { x = *this; } /* template inline void operator () (T &x, A &...a) */ /* { x = *this; this -> operator () (a...); } */ } read; const int maxn = 55; int a[maxn][maxn]; bool die[maxn]; int main () { int q = read; while (q --) { int n = read, lang = 0; for (int i = 1; i <= n; i ++) if (int(read) == 1) lang = i; for (int i = 1; i <= n; i ++) for (int j = 1; j <= n; j ++) read(a[i][j]); std::fill(die, die + n + 1, 0); int now = a[lang][1]; for (int tot = n; tot; tot --) { die[now] = 1; if (now == lang) { puts("lieren"); break; } if (tot - 1 <= 2) { puts("langren"); break; } int nxt = 0; for (int i = n; i; i --) if (!die[a[now][i]]) nxt = a[now][i]; now = nxt; } } }