#include <bits/stdc++.h>
using namespace std;
#define ll long long int
void solve() {
 ll n,r=0,c=0,k=1;;
 cin>>n;ll a[n][n];
 if(n==1)
 {cout<<"1\n";return;}
 if(n==2)
 {cout<<"-1\n";return;}
 else
 {if(n%2==0)
 {
 while(k<=n*n-1)
 {a[r][c++]=k;k+=2;
 if(c==n ) {r++;c=0;}
 }k=2;
 while(r<=n-1)
 {a[r][c++]=k;k+=2;
 if(c==n ) {r++;c=0;}
 }}
 else
 {
 while(k<=n*n)
 {a[r][c++]=k;k+=2;
 if(c==n ) {r++;c=0;}
 }k=2;
 while(r<=n-1)
 {a[r][c++]=k;k+=2;
 if(c==n ) {r++;c=0;}
 }}}
 
 
 
for(ll i=0;i<n;i++)
{for(ll j=0;j<n;j++)
{cout<<a[i][j]<< " ";}
cout<<"\n";
}

}

int main() {
  int tests;ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  cin >> tests;
  while (tests-- > 0) {
    solve();
  }
  return 0;
}