#include using namespace std; int a[55][55]; int id[55]; bool live[55]; int main() { // memset(c, 0, sizeof c); int t; scanf("%d", &t); while(t--){ int n; scanf("%d", &n); int s; for(int i = 1; i <= n; ++i){ scanf("%d", id + i); live[i] = true; if(id[i] == 1) s = i; } for(int i = 1; i <= n; ++i){ for(int j = 1; j <= n; ++j){ scanf("%d", &a[i][j]); } } int tot = n; while(true){ int dead = -1; for(int i = 1; i <= n; ++i){ if(live[a[s][i]]){ live[a[s][i]] = false; dead = a[s][i]; tot--; break; } } if(!live[s]){ printf("lieren\n"); break; } if(tot <= 2){ printf("langren\n"); break; } bool ok = false; while(true){ for(int i = 1; i <= n; ++i){ if(live[a[dead][i]]){ live[a[dead][i]] = false; dead = a[dead][i]; tot--; break; } } if(!live[s]){ printf("lieren\n"); ok = true; break; } if(tot <= 2){ printf("langren\n"); ok = true; break; } } if(ok) break; } } return 0; } // 12 33