#include using namespace std; int t,s,x,n,i,j,a[55],p[55][55]; bool b[55],g; int main() { scanf("%d",&t); while(t--) { scanf("%d",&n); memset(b,0,sizeof(b)); for(i=1;i<=n;i++)scanf("%d",a+i); for(i=1;i<=n;i++)for(j=1;j<=n;j++)scanf("%d",p[i]+j); for(s=1;s<=n;s++)if(a[s])break; for(x=p[s][1],i=1;;i++) { if(x==s) { g=1; break; } if(n-i<=2) { g=0; break; } b[x]=1; for(j=1;j<=n;j++)if(!b[p[x][j]])break; x=p[x][j]; } if(g)puts("lieren"); else puts("langren"); } return 0; }