# include using namespace std; # define rep(i,a,n) for (int i=a; i<=n; ++i) # define per(i,a,n) for (int i=a; i>=n; --i) # define bug puts("H"); # define pb push_back # define mp make_pair # define all(x) (x).begin(), (x).end() # define fi first # define se second # define lch p<<1,l,mid # define rch p<<1|1,mid+1,r # define mem(a,b) memset(a,b,sizeof(a)) # define INF 1000000001 # define MOD 998244353 typedef vector Vi; typedef long long i64; typedef long long ll; typedef pair Pi; //i64 powmod(i64 a, i64 b, i64 mod){i64 res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} //i64 Inv(i64 b){return powmod(b,(i64)MOD-2);} inline int Scan() { int x=0; char ch=getchar(); while(ch<'0'||ch>'9') ch=getchar(); while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();} return x; } const int N = 505; //const int M = 524288; const double eps = 1e-9; int g[N][N]; int f[N], pos; bool comp(int a, int b) {return a > b;} int main () { int T; scanf("%d", &T); while (T--) { int n, x, y; scanf("%d%d%d", &n, &x, &y); rep(i,1,n) rep(j,1,n) scanf("%d", &g[i][j]); int ans = INF, pi, pj; rep(i,1,n) rep(j,1,n) { int tmp = (abs(i-x)+abs(j-y)+1)/2; int food = 0; pos = 0; f[++pos] = g[i][j]; rep(k,max(1,i-3),min(n,i+3)) rep(l,max(1,j-3),min(n,j+3)) { if (abs(k-i)+abs(l-j) <= 3) { if (k!=i || l!=j) f[++pos] = g[k][l]; } } sort(f+2, f+pos+1, comp); rep(k,pos+1,8) f[k] = 0; rep(k,1,8) { f[k] += f[k-1]; int ct = (8*k*k-food+f[k]-1)/f[k]; tmp += ct; //cout << ct << endl; food += ct*f[k]; } if (ans > tmp) pi = i, pj = j; ans = min(ans, tmp); } printf("%d\n", ans); //cout << pi << " " << pj << endl; } return 0; }