/* Author : zzugzx Lang : C++ Blog : blog.csdn.net/qq_43756519 */ #include using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define endl '\n' #define SZ(x) (int)x.size() typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef pair pll; const int mod = 1e9 + 7; const int MOD = 998244353; const double eps = 1e-6; const double pi = acos(-1.0); const int maxn = 1e6 + 10; const int N = 4e3 + 10; const ll inf = 0x3f3f3f3f; const int dir[][2]={{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; int g[510][510]; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); int _; cin >> _; while (_--) { int n, x, y; cin >> n >> x >> y; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> g[i][j]; ll ans = inf, tmp, cnt, s = 0, now = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { tmp = (abs(x - i) + abs(y - j) + 1) / 2; cnt = 1; s = g[i][j], now = 0; priority_queue pq; for (int p = max(1, i - 3); p <= min(i + 3, n); p++) for (int q = max(1, j - 3); q <= min(j + 3, n); q++){ if (p == i && q == j)continue; if (abs(i - p) + abs(j - q) <= 3) pq.push(g[p][q]); } while (cnt < 9) { now += s; if (now >= 8 * cnt * cnt) { cnt++; if (pq.size()){ s += pq.top(); pq.pop(); } } ++tmp; } ans = min(ans, tmp); } cout << ans << endl; } return 0; }