#include using namespace std; const int N=1000005,M=1000000007; int t,n,m,i,j,p[55],a[505][505],k,x,y,d[505][505]; long long qpow(long long a,long long b) { long long s=a,ans=1; while(b) { if(b&1) ans=ans*s%M; s=s*s%M; b>>=1; } return ans; } bool cmp(int a,int b) { return a>b; } int main(){ scanf("%d",&t); while(t--) { scanf("%d %d %d",&n,&x,&y); for(i=1;i<=n;++i) for(j=1;j<=n;++j) scanf("%d",&a[i][j]); int ans=1<<30; for(i=1;i<=n;++i) for(j=1;j<=n;++j) { int dis=(abs(x-i)+abs(y-j)+1)/2; k=0; memset(p,0,sizeof(p)); for(int x=-3;x<=3;++x) for(int y=-3;y<=3;++y) if(abs(x)+abs(y)<=3&&abs(x)+abs(y)>=1) if(i+x>=1&&j+y>=1&&i+x<=n&&j+y<=n) p[++k]=a[i+x][j+y]; sort(p+1,p+1+k,cmp); int dt=a[i][j]; int l=1,d=1,s=0; int x; for(x=1;;++x) { s+=dt; while(s>=8*d*d) { ++d; dt+=p[l++]; } if(d>=9) break; } ans=min(ans,x+dis); } cout<