#include using namespace std; inline int mdd(int x1, int y1, int x2, int y2) { return abs(x1 - x2) + abs(y1 - y2); } int n, a[505][505]; inline int solve(int sx, int sy) { vector vec; for (int dx = -3; dx <= 3; dx++) { for (int dy = -3; dy <= 3; dy++) if (abs(dx) + abs(dy) <= 3 && (dx || dy)) { int x = sx + dx, y = sy + dy; if (x >= 1 && x <= n && y >= 1 && y <= n) { vec.push_back(a[x][y]); } } } while (vec.size() < 9) vec.push_back(0); sort(vec.begin(), vec.end()); int c = 1, dlt = a[sx][sy], sum = 0, hh = 0; while (c < 9) { hh++; sum += dlt; if (sum >= 8 * c * c) { dlt += vec.back(); c++; vec.pop_back(); } } return hh; } int main() { int T, x, y; scanf("%d", &T); while (T--) { 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]); } int ans = 1e9; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { ans = min(ans, solve(i, j) + (mdd(i, j, x, y) + 1) / 2); } } printf("%d\n", ans); } return 0; }