#include #include #include #define N 53 using namespace std; inline int read(){ int x=0,f=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')f=-1; c=getchar(); } while(c>='0'&&c<='9'){ x*=10;x+=c-'0'; c=getchar(); } return x*f; } int wankil[N][N],point[N]; int lang,n; inline void scan(){ n=read(); int ttt; for(int i=1;i<=n;i++){ ttt=read(); if(ttt)lang=i; } for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) wankil[i][j]=read(); } int death; bool pan[N]; inline void suan(){ death=lang; for(int i=1;i<=n;i++)point[i]=1; memset(pan,0,n+2); if(lang==wankil[lang][1]){ printf("lieren\n"); return; } for(int i=1;i<=n-2;i++){ while(pan[wankil[death][point[death]]]||death==wankil[death][point[death]]) point[death]++; int yy=wankil[death][point[death]]; death=yy; if(death==lang){ printf("lieren\n"); return; } pan[yy]=1; } printf("langren\n"); } int main(){ int T; T=read(); for(int i=1;i<=T;i++){ scan(); suan(); } }