#pragma comment(linker, "/stack:200000000") #include using namespace std; typedef long long ll; typedef pair pii; #define Rep(i,a,b) for(register int i=(a);i<=int(b);++i) #define Dep(i,a,b) for(register int i=(a);i>=int(b);--i) #define rep(i,a,b) for(register int i=(a);i=10)write(x/10);putchar(x%10+'0');} void wri(ll x){write(x);pc(' ');} void writeln(ll x){write(x);pc('\n');} const int mod = 998244353; const int maxn = 1e7+233; int a[505][505],n; int calc(int x,int y){ vector vec; vec.clear(); Rep(i,-3,3)Rep(j,-3,3)if(abs(i)+abs(j)<=3&&abs(i)+abs(j)!=0){ if(1<=x+i&&x+i<=n&&1<=y+j&&y+j<=n) vec.push_back(a[x+i][y+j]); } sort(vec.begin(),vec.end()); vec.push_back(a[x][y]); reverse(vec.begin(),vec.end()); rep(i,1,vec.size()) vec[i] += vec[i-1]; int p = 1,food = 0,tim = 1; int R = vec.size() - 1; while(p < 9){ food += vec[min(R,p-1)]; while(food >= 8 * p * p) p++; if(p >= 9) break; tim++; } return tim; } void solve(){ int x,y; n = read(),x = read(),y = read(); Rep(i,1,n){ Rep(j,1,n) a[i][j] = read(); } int ans = 0x3f3f3f3f; Rep(i,1,n){ Rep(j,1,n){ int w = abs(x-i) + abs(y-j); int t0 = (w-1) / 2 + 1; if(w==0) t0 = 0; if(t0 <= ans) ans = min(ans,t0+calc(i,j)); } }writeln(ans); } int main(){ int T = read(); while(T--) solve(); }