#include #define mst(a,b) memset(a,b,sizeof(a)) #define lowbit(x) ((x)&(-x)) #define X first #define Y second #define lc o<<1 #define rc o<<1|1 using namespace std; typedef long long LL; typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef pair pdd; typedef pair pll; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; const int maxn = 500+10; const int maxm = 100000+10; const int mod = 1e9+7; const double eps = 1e-8; int nx[24][2]={{-3,0}, {-2,-1}, {-2,0}, {-2,1}, {-1,-2}, {-1,-1}, {-1,0}, {-1,1}, {-1,2}, {0,-3}, {0,-2}, {0,-1}, {0,1}, {0,2}, {0,3}, {1,-2}, {1,-1}, {1,0}, {1,1}, {1,2}, {2,-1}, {2,0}, {2,1}, {3,0}}; int a[maxn][maxn],res[maxn][maxn]; int main() { #ifdef local freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); int T; cin>>T; while (T--){ int n,x,y; cin>>n>>x>>y; for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) cin>>a[i][j]; for (int i=1;i<=n;i++) for (int j=1;j<=n;j++){ vector b; for (int k=0;k<24;k++){ int dx=i+nx[k][0],dy=j+nx[k][1]; if (1<=dx && dx<=n && 1<=dy && dy<=n){ b.emplace_back(a[dx][dy]); } } sort(b.begin(),b.end()); reverse(b.begin(),b.end()); int food=0,add=a[i][j],cur=0; res[i][j]=0; for (int k=2;k<=9;k++){ int d=8*(k-1)*(k-1)-food; assert(d>=0); int tmp=d/add; if (d%add) tmp++; food+=tmp*add; res[i][j]+=tmp; if (cur<(int)b.size()) add+=b[cur++]; } } int ans=inf; for (int i=1;i<=n;i++) for (int j=1;j<=n;j++){ int dis=abs(x-i)+abs(y-j); int tot=(dis/2)+(dis&1)+res[i][j]; ans=min(ans,tot); } cout<