#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define ss second
#define ff first
#define mx 100005
using namespace std;

int main(){
    ll t; cin>>t;
    while(t--){
        ll n ; cin>>n;
        if(n==1){
            cout<<1<<endl;
            continue;
        }
        if(n==2){
            cout<<-1<<endl;
            continue;
        }
        ll jr=4 , b=1 ;
        vector<ll>v[n];
        for(int i=0 ; i<n  ; i++ ){
            for(int j=0 ; j<n ; j++){
                if(i%2==0){
                    if(b>n*n){
                        v[i].push_back(2);
                        b=jr;
                    }
                    else{
                        v[i].pb(b);
                        b+=2;
                    }

                }
                else{
                    if(jr>n*n)jr=2;
                    v[i].pb(jr);
                    jr+=2;
                }
            }
        }

        for(int i=0 ; i<n  ; i++ ){
            for(int j=0 ; j<n ; j++){
                    cout<<v[i][j]<<" ";
            }
            cout<<endl;
        }

    }
}
