#include #define LL long long #define dl double template void rd(T &x){ x=0;T f=1;char ch=getchar(); while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch<='9' && ch>='0')x=x*10+ch-'0',ch=getchar();x*=f; } using namespace std; const int N=505; int T; int n,X,Y; int a[N][N]; vectorS; int s[N],tot; bool cmp(int x,int y){return x>y;} int work(int x,int y){ S.clear(); for(int i=max(1,x-3);i<=min(n,x+3);i++){ int tmp=3-abs(x-i); for(int j=max(1,y-tmp);j<=min(n,y+tmp);j++){ if(i == x && y == j)continue; S.push_back(a[i][j]); } } sort(S.begin(),S.end(),cmp); tot=S.size();s[0]=a[x][y]; for(int i=0;i= 8*(per+1)*(per+1))per++; } return day; } int main(){ // freopen("in.txt","r",stdin); // freopen("o.txt","w",stdout); rd(T); while(T--){ rd(n);rd(X);rd(Y); int ans=0x7fffffff; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) rd(a[i][j]); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) ans=min(ans,(abs(i-X)+abs(j-Y)+1)/2+work(i,j)); printf("%d\n",ans); } return 0; } /**/