#include using namespace std; const int maxn=55; const int mode=1e9+7; int read(){ int x=0,f=1;char ch=getchar(); while(!isdigit(ch)){ if(ch=='-') f=-1; ch=getchar(); } while(isdigit(ch)){ x=x*10+ch-'0'; ch=getchar(); } return x*f; } int t,n; int si[maxn],dp[maxn][maxn],cur,wo; int main(){ t=read(); while(t--){ n=read(); cur=1; for(int i=1;i<=n;++i){ si[i]=read(); if(si[i]==1) wo=i; } for(int i=1;i<=n;++i){ for(int j=1;j<=n;++j){ dp[i][j]=read(); } } bool juge=false; int cnt=n,temp; while(cnt>2){ if(cnt==n){ temp=dp[wo][1]; } else{ for(int i=1;i<=n;++i){ if(dp[temp][i]==wo||si[dp[temp][i]]==0){ temp=dp[temp][i]; break; } } } cnt--; si[temp]=1; if(temp==wo){ juge=true; break; } else{ if(cnt<=2) break; } } if(juge) printf("lieren\n"); else printf("langren\n"); } }