import java.util.ArrayDeque; import java.util.Scanner; public class knight { static int n; static ArrayDeque q; static int d=-1; public static void eval(int a, int b,boolean[][] ar){ loc curr=q.poll(); int[] t={a,-a,b,-b}; for(int i=0;i<4;i++) for(int k=i<2?2:0;k<(i<2?4:2);k++) if(curr.x+t[i]>=0 && curr.y+t[k]>=0 &&curr.x+t[i](); q.add(new loc(0,0,0)); while(!q.isEmpty()){ eval(x, y, b); } ans[x-1][y-1]=ans[y-1][x-1]=d; d=-1; } String s=""; for(int[] a:ans){ for(int i:a){ s+=i+" "; } s=s.substring(0,s.length()-1)+"\n"; } System.out.print(s); } } class loc{ int x,y,dis; public loc(int a,int b, int c){ x=a; y=b; dis=c; } }