#include using namespace std; int cas,n,x,y,a[505][505]; inline int get(int x,int y) { vector vec; int now=a[x][y]; for (int i=x-3;i<=x+3;++i) for (int j=y-3;j<=y+3;++j) { if (i<1||i>n||j<1||j>n) continue; int d=abs(x-i)+abs(y-j); if (d<=3&&d>0) vec.push_back(a[i][j]); } sort(vec.begin(),vec.end()); reverse(vec.begin(),vec.end()); int tot=0,man=1; for (int i=1;;++i) { tot+=now; while (tot>=8*man*man) { if (man<=(int)vec.size()) { now+=vec[man-1]; } ++man; } if (man>=9) return i; } } int main() { scanf("%d",&cas); while (cas--) { 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 res=10000; for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) res=min(res,get(i,j)+(abs(i-x)+abs(j-y)+1)/2); printf("%d\n",res); } return 0; }