#include #define LL long long #define Max(a,b) ((ab)&&(a=b)) #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i) #define erep(i,a) for(int i=hd[a],y;(y=to[i]);i=nxt[i]) using namespace std; char C; inline int rd() { int res=0,f=1; while(C=getchar(),C<48||C>57)if(C=='-')f=0; do res=(res<<3)+(res<<1)+(C^48); while(C=getchar(),C>=48&&C<=57); if(f)return res; return -res; } int n,a[505][505],ans,sx,sy; priority_queueq; bool ok(int x,int y){ return x>0&&y>0&&x<=n&&y<=n; } void solve(int x,int y,int stp){ int t=a[x][y],res=stp; while(q.size())q.pop(); rep(i,-3,3)rep(j,-3,3)if(abs(i)+abs(j)<=3){ if(i==0&&j==0)continue; if(ok(x+i,y+j))q.push(a[x+i][y+j]); } int nw=0; rep(i,1,8){ int tmp=(8*i*i-nw-1)/t+1; res+=tmp,nw+=t*tmp; if(q.size())t+=q.top(),q.pop(); } Min(ans,res); } int main() { int T=rd(); while(T--){ n=rd(),sx=rd(),sy=rd(),ans=2e9; rep(i,1,n)rep(j,1,n)a[i][j]=rd(); rep(i,1,n)rep(j,1,n) solve(i,j,(abs(sx-i)+abs(sy-j)+1)/2); printf("%d\n",ans); } }