#include using namespace std; int n, a[55], b[55][55], alive[55]; int main() { int T; scanf("%d", &T); while (T--) { scanf("%d", &n); int wf = -1; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (a[i]) wf = i; alive[i] = 1; } for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &b[i][j]); int p = b[wf][1]; int res; while (true) { alive[p] = 0; if (p == wf) { res = 1; break; } int cnt = 0; for (int i = 1; i <= n; i++) if (alive[i]) cnt++; if (cnt <= 2) { res = 0; break; } for (int i = 1; i <= n; i++) if (alive[b[p][i]]) { p = b[p][i]; break; } } if (res) puts("lieren"); else puts("langren"); } return 0; }