http://acm.hdu.edu.cn/showproblem.php?pid=1998
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<iomanip>
using namespace std;
const int inf=10000000;
int map[23][23];
int main(){
int T; cin>>T;
while(T--){
int n; cin>>n;
memset(map,0,sizeof(map));
int x=1,y=n/2+1;
map[x][y]=1;
for(int i=2;i<=n*n;++i){
x--,y++;
if(x<1)x=n;
if(y>n)y=1;
int q=0;
while(map[x][y]){
if(!q)x+=2,--y;
else x++;
if(x>n)x=1;
if(y<1)y=n;
if(x<1)x=n;
if(y>n)y=1;
q=1;
}
map[x][y]=i;
}
for(int i=1;i<=n;++i){
cout<<setw(4)<<map[i][1];
for(int j=2;j<=n;++j)
cout<<setw(4)<<map[i][j];
cout<<endl;
}
}
return 0;
}