#include using namespace std; int main() { ios::sync_with_stdio(false); int test; cin >> test; while (test--) { int n, x, y; cin >> n >> x >> y, --x, --y; vector> a(n); for (int i = 0; i < n; ++i) { a[i].resize(n); for (int j = 0; j < n; ++j) { cin >> a[i][j]; } } int ans = 1 << 30; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { vector all; int now = a[i][j]; for (int k = i - 3; k <= i + 3; ++k) { for (int l = j - 3; l <= j + 3; ++l) { if (k >= 0 && k < n && l >= 0 && l < n && abs(k - i) + abs(l - j) <= 3) { if (k == i && l == j) { continue; } all.push_back(a[k][l]); } } } sort(all.begin(), all.end(), greater()); int cnt = (abs(i - x) + abs(j - y) + 1) / 2, food = 0; for (int i = 1; i < 9; ++cnt) { food += now; if (food >= 8 * i * i) { if (i - 1 < all.size()) { now += all[i - 1]; } ++i; } } ans = min(ans, cnt); } } cout << ans << '\n'; } }