#include #define ll long long #define uint unsigned int #define ull unsigned long long #define inf 1010000000 #define infll 1010000000000000000ll #define vi vector #define vll vector #define pb push_back #define pii pair #define pll pair #define pdd pair #define mpr make_pair #define fi first #define se second #define pq priority_queue #define pqll priority_queue #define up(x,y) (x<(y)?x=(y):0) #define dn(x,y) (x>(y)?x=(y):0) #define ad(x,y) (x=(x+(y))%mod) #define cbn(x,y) ((ll)fac[x]*inv[y]%mod*inv[(x)-(y)]%mod) using namespace std; int read(); ll readll(); int n, a[59], b[59][59]; bool live[59]; int main(){ int cas = read(); while (cas--){ scanf("%d", &n); int i, j, sta; for (i = 1; i <= n; i++){ scanf("%d", &a[i]); if (a[i]) sta = i; } for (i = 1; i <= n; i++) live[i] = true; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) scanf("%d", &b[i][j]); int k = sta; bool flag = true; for (i = 1; i <= n - 2; i++){ for (j = 1; j <= n; j++) if (live[b[k][j]]){ k = b[k][j]; live[k] = false; if (k == sta){ puts("lieren"); flag = false; break; } break; } } if (flag) puts("langren"); } return 0; } int read(){ int x=0; char ch=getchar(); bool flag=0; while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); } while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); } return flag?-x:x; } ll readll(){ ll x=0; char ch=getchar(); bool flag=0; while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); } while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); } return flag?-x:x; }