#include using namespace std; typedef long long ll; typedef pair PII; const int N = 50 + 5, mod = 1e9 + 7; int T, n, id[N], q[N][N], hh[N]; bool die[N]; int main() { ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin >> T; while(T--) { cin >> n; int wolf; for(int i = 1; i <= n; i++) { cin >> id[i]; die[i] = 0; hh[i] = 1; if(id[i]) wolf = i; } for(int i = 1; i <= n; i++) for(int j = 1, k; j <= n; j++) { cin >> k; q[i][j] = k; } int res = n, ans; while(1) { int &h = hh[wolf]; while(die[q[wolf][h]]) h++; int top = q[wolf][h++]; die[top] = 1; res--; if(id[top]) { ans = 1; break; } else if(res == 2) { ans = 0; break; } bool over = false; while(1) { int &h1 = hh[top]; while(die[q[top][h1]]) h1++; int top1 = q[top][h1++]; die[top1] = 1; res--; if(id[top1]) { ans = 1; over = true; break; } else if(res == 2) { ans = 0; over = true; break; } top = top1; } if(over) break; } if(ans) cout << "lieren\n"; else cout << "langren\n"; } return 0; }