#pragma GCC optimize(2) #include #define all(n) (n).begin(), (n).end() #define se second #define fi first #define pb emplace_back #define mp make_pair #define sqr(n) ((n)*(n)) #define rep(i, a, b) for (int i = (a); i <= (b); ++i) #define per(i, a, b) for (int i = (a); i >= (b); --i) #define precision(a) setiosflags(ios::fixed) << setprecision(a) #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair PII; typedef pair PLL; typedef vector VI; typedef vector VL; typedef double db; template inline char read(T& x) { x = 0; T fg = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') fg = -1; ch = getchar(); } while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ '0'), ch = getchar(); x = fg * x; return ch; } template inline void read(T& x, Args &... args) { read(x), read(args...); } template inline void write(T x) { int len = 0; char c[40]; if (x < 0) putchar('-'), x = -x; do { ++len; c[len] = x % 10 + '0'; } while (x /= 10); for (int i = len; i >= 1; i--) putchar(c[i]); } template inline void write(T& x, Args &... args) { write(x), write(args...); } template bool umin(T1& a, T2 b) { return a > b ? (a = b, true) : false; } template bool umax(T1& a, T2 b) { return a < b ? (a = b, true) : false; } template void clear(T& a) { T().swap(a); } const int N = 1e5 + 5; int n, m, _, k, cas; int a[55][55], cnt[55]; bool v[55]; bool check() { if (m == 0) return cout << "lieren\n", 1; if (n <= 2) return cout << "langren\n", 1; return 0; } bool work(int x) { if (x == m) m = 0; --n, v[x] = 1; if (check()) return 1; while (v[a[x][cnt[x]]]) ++cnt[x]; if (work(a[x][cnt[x]++])) return 1; return 0; } int main() { IOS; for (cin >> _; _; --_) { cin >> n; m = 0; for (int i = 1; i <= n; v[i++] = 0) { bool f; cin >> f; if (f) m = i; } for (int i = 1; i <= n; cnt[i++] = 1) for (int j = 1; j <= n; ++j) cin >> a[i][j]; work(a[m][cnt[m]]); } return 0; }