#include <bits/stdc++.h>
using namespace std;
#define ll long long  
#define pb push_back 
#define mk make_pair

ll m=1000000007; 
ll fact(ll n); 

int modInverse(int a, int m) 
{ 
    int m0 = m; 
    int y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        int q = a / m; 
        int t = m; 
  
        m = a % m, a = t; 
        t = y; 
  
        y = x - q * y; 
        x = t; 
    } 
  
    if (x < 0) 
       x += m0; 
  
    return x; 
} 


ll fact(ll n) 
{ 
    ll res = 1; 
    for (ll i = 2; i <= n; i++) 
        res = (res%m * i%m)%m; 
    return res; 
} 
 
int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll t;
        cin>>t;
        while(t--){
            ll n,an=1,m;
            cin>>n;
            if(n==2){
                cout<<"-1\n";
                continue;
            }
            if(n%2==1)
            m=n*n;
            else
            m=n*n-1;
            for(ll i=0;i<n;i++){
                for(ll j=0;j<n;j++){
                    cout<<an<<" ";
                    if(an==m){
                        an=2;
                    }else{
                        an+=2;
                    }
                }
                cout<<endl;
            }
            
        }
    return 0;
}