#include #include #include #include using namespace std; const int Maxn = 510; int n, X, Y; int a[Maxn][Maxn]; int p[110], pl; int _min(int x, int y) { return x < y ? x : y; } int _abs(int x) { return x < 0 ? -x : x; } int main() { int i, j, k; int T; scanf("%d", &T); while(T--){ scanf("%d%d%d", &n, &X, &Y); for(i = 1; i <= n; i++) for(j = 1; j <= n; j++) scanf("%d", &a[i][j]); int ans = 10000; for(i = 1; i <= n; i++){ for(j = 1; j <= n; j++){ pl = 0; p[++pl] = -a[i][j]; for(int x = -3; x <= 3; x++){ int t = 3-_abs(x); for(int y = -t; y <= t; y++){ if(x == 0 && y == 0) continue; if(i+x < 1 || i+x > n || j+y < 1 || j+y > n) continue; p[++pl] = -a[i+x][j+y]; } } sort(p+2, p+pl+1); int prod = 0, now = 0, sum = 0; for(k = 1; k <= 8; k++){ if(k <= pl) prod += -p[k]; int u = (8*k*k-now-1)/prod+1; sum += u; now += u*prod; } ans = _min(ans, sum+(_abs(i-X)+_abs(j-Y)+1)/2); //if(ans == 10) printf("%d %d\n", i, j); } } printf("%d\n", ans); } return 0; }