#include typedef int LL; typedef double dl; #define opt operator #define pb push_back const LL maxn=1e3+9,mod=998244353,inf=0x3f3f3f3f; LL Read(){ LL x(0),f(1); char c=getchar(); while(c<'0' || c>'9'){ if(c=='-') f=-1; c=getchar(); } while(c>='0' && c<='9'){ x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar(); }return x*f; } void Chkmin(LL &x,LL y){ if(yx) x=y; } LL add(LL x,LL y){ return x+=y,x>=mod?x-mod:x; } LL dec(LL x,LL y){ return x-=y,x<0?x+mod:x; } LL mul(LL x,LL y){ return 1ll*x*y%mod; } LL T; LL n,X,Y; LL a[maxn][maxn],b[maxn]; LL Check(LL x,LL y){ return x>=1 && x<=n && y>=1 && y<=n; } int main(){ T=Read(); while(T--){ n=Read(); X=Read(); Y=Read(); for(LL i=1;i<=n;++i){ for(LL j=1;j<=n;++j){ a[i][j]=Read(); } } LL ans(inf); for(LL s=1;s<=n;++s){ for(LL t=1;t<=n;++t){ LL Tmp(std::abs(s-X)+std::abs(t-Y)); Tmp=(Tmp+1)/2; LL tot(0); for(LL i=-3;i<=3;++i){ for(LL j=-3;j<=3;++j){ if(i==0 && j==0) continue; LL nw(std::abs(i)+std::abs(j)); if(nw>3) continue; if(Check(s+i,j+t)) b[++tot]=a[s+i][j+t]; } } LL nw=a[s][t],sum(0); std::sort(b+1,b+1+tot); LL num(1); for(LL i=1;;++i){ sum+=nw; if(sum>=num*num*8){ ++num; if(tot) nw+=b[tot--]; if(num==9){ Chkmin(ans,Tmp+i); break; } } } } } printf("%d\n",ans); } return 0; }/* 1 10 9 8 1 2 2 1 2 3 1 1 2 1 2 1 3 3 3 2 3 2 3 1 1 1 3 1 1 3 2 2 1 2 3 1 3 1 3 3 1 3 1 3 3 2 3 1 3 1 2 2 2 1 2 3 2 3 2 2 3 1 2 3 3 1 3 3 2 2 3 2 3 3 1 3 3 2 3 2 2 2 1 1 3 3 1 2 3 2 1 2 1 2 1 1 3 1 3 1 1 1 3 3 */