#include using namespace std; namespace jumpmelon { const int MAXN = 500; int A[MAXN + 1][MAXN + 1]; void work() { int kase; scanf("%d", &kase); while (kase--) { int n, x, y, ans = INT_MAX; scanf("%d%d%d", &n, &x, &y); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &A[i][j]); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { vector V; V.push_back(A[i][j]); for (int dx = -3; dx <= 3; dx++) { int xx = i + dx, lim = 3 - abs(dx); for (int dy = -lim; dy <= lim; dy++) if (dx || dy) { int yy = j + dy; if (1 <= xx && xx <= n && 1 <= yy && yy <= n) V.push_back(A[xx][yy]); } } if (V.size() > 1) sort(V.begin() + 1, V.end(), greater()); int s = V[0], c = 1, cur = 0, w = 0; while (c < 9) { w++; cur += s; if (cur >= 8 * c * c) { if (c < V.size()) s += V[c]; c++; } } ans = min(ans, (abs(x - i) + abs(y - j) + 1) / 2 + w); } printf("%d\n", ans); } } } int main() { jumpmelon::work(); return 0; }