#include #include #include #include #include using namespace std; struct data{ int x,y,w; }mpt[100]; int T,n,x,y,ans,cnt,food,tot,now,nx,ny; int a[510][510]; int read() { static int x; static char ch; x = 0; for (ch = getchar();ch>'9' || ch<'0';ch=getchar()); for (;ch <='9' && ch >='0';ch=getchar()) x = x * 10 + ch - '0'; return x; } void readln() { n = read();x = read();y = read(); for (int i = 1;i<=n;++i) for (int j = 1;j<=n;++j) a[i][j] = read(); ans = -1; } bool cmp(data a,data b) { return a.w > b.w; } void find_ans(int tx,int ty) { int pt = abs(tx - x) + abs(ty - y); food = 0;tot=0;now = 0; cnt = (pt >> 1) + (pt & 1); for (int i = -3;i<=3;++i) for (int j = -3;j<=3;++j) if (abs(i) + abs(j) <= 3 && abs(i) + abs(j) > 0) { nx = tx + i;ny = ty + j; if (nx <= 0 || ny <= 0 || nx > n || ny > n) continue; mpt[++tot] = (data){nx,ny,a[nx][ny]}; } sort(mpt+1,mpt+1+tot,cmp); pt = 8 / a[tx][ty] + (8 % a[tx][ty] != 0); cnt += pt; food = a[tx][ty] * pt; now = a[tx][ty]; for (int i = tot+1;i<=7;++i) mpt[i].w = 0; for (int i = 2;i<=8;++i) { now += mpt[i-1].w; pt = (8 * i * i - food) / now + ((8 * i * i - food) % now != 0); cnt += pt; food += now * pt; } if (ans == -1 || cnt < ans) ans = cnt; } void solve() { for (int i = 1;i<=n;++i) for (int j = 1;j<=n;++j) find_ans(i,j); cout << ans << endl; } int main() { T = read(); for (int i = 1;i<=T;++i) { readln(); solve(); } return 0; }