#include #define fo(i,a,b) for(int i=a;i<=b;i++) #define fod(i,a,b) for(int i=a;i>=b;i--) #define me0(a) memset(a,0,sizeof(a)) #define me1(a) memset(a,-1,sizeof(a)) #define op freopen("in.txt", "r", stdin) #define pii pair #define mp(x,y) make_pair(x,y) using namespace std; const int INF = 0x3f3f3f3f; typedef unsigned long long ULL; typedef long long LL; void read(int& val) { int x = 0; int bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; } const int mod=998244353; const int maxn=1e6+10; int n,x,y; int g[510][510]; vectorv; int ans[510][510]; int cal(vectora,int v){ sort(a.begin(),a.end()); reverse(a.begin(),a.end()); int pos = 0,sz = a.size(),num=1; int sum=0,add=v,tim=0; while(num<9){ sum+=add;tim++; if(sum>=8*(num*num)){ num++; if(pos<=sz-1){ add+=a[pos];pos++; } } } return tim; } void solve(){ fo(i,1,n){ fo(j,1,n){ fo(k,-3,3){ fo(z,-3,3){ if(abs(k)+abs(z)>3) continue; int nx = i+k,ny = j+z; if(nx<1||nx>n||ny<1||ny>n) continue; if(k==0&&z==0) continue; v.emplace_back(g[nx][ny]); } } ans[i][j]=cal(v,g[i][j]); v.clear(); } } } int main(){ // op; int t;read(t); while(t--){ read(n);read(x);read(y); fo(i,1,n) fo(j,1,n) read(g[i][j]); solve(); int res = INF; vectorrrr; fo(i,1,3) rrr.push_back(1); fo(i,1,n){ fo(j,1,n){ int tm = (abs(i-x)+abs(j-y)+1)/2; res=min(res,tm+ans[i][j]); } } printf("%d\n",res); } return 0; }