//Awwawa! Dis cold yis ratten buy tEMMIE! #include #define ll long long #define maxn 505 /*rem*/ #define mod 998244353 #define db double #define vi vector #define pb push_back #define mp make_pair #define pi pair #define fi first #define se second template bool chkmax(T &x,T y){return x bool chkmin(T &x,T y){return x>y?x=y,true:false;} using namespace std; ll ksm(ll a, ll b) { if (!b) return 1; ll ns = ksm(a, b >> 1); ns = ns * ns % mod; if (b & 1) ns = ns * a % mod; return ns; } int a[maxn][maxn]; int main() { int test; cin >> test; while (test--) { int n, x, y; cin >> n >> x >> y; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]); int ans = 1e9; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { vi cur; cur.pb(a[i][j]); for (int k = i - 3; k <= i + 3; k++) for (int l = j - 3; l <= j + 3; l++) { if (k < 1 || l < 1 || k > n || l > n) continue; if (abs(k - i) + abs(l - j) > 3) continue; if (k == i && l == j) continue; cur.pb(a[k][l]); } sort(cur.begin() + 1, cur.end()); reverse(cur.begin() + 1, cur.end()); cur.resize(9); int t = 0; int s = cur[0], tot = 0; for (int i = 1; i <= 8; i++) { //得到 i + 1个人 int nd = 8 * i * i; if (tot < nd) { int td = (nd - tot + s - 1) / s; t += td; tot += s * td; } s += cur[i]; } int dv = abs(i - x) + abs(j - y); t += (dv + 1) / 2; chkmin(ans, t); } printf("%d\n", ans); } return 0; }