#include <iostream>
#include<bits/stdc++.h>
#define ll long long
 
using namespace std;
 
int main() {
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        if(n==1)cout <<1<< endl;
        else if(n==2)cout << -1 << endl;
        else
        {
            ll a=1;
            ll b = 4;
            for(ll i = 0;i<n;i++)
            {
                if(i%2==0){
                    for(ll j=a;;j+=2)
                    {
                        if(j>a+2*(n)-1 ){
                            a=j;
                            cout << endl;
                            break;
                        }
                        if(j>n*n)
                        {   
                            a=j;
                            break;
                        }
                        cout << j << " ";
                        
                    }

                }
                else if(i%2==1)
                {
                    
                    for(ll j =b;;j+=2)
                    {
                        if(j>b+2*(n)-2 ){
                            b= j;
                            cout << endl;
                            break;
                        }
                        if(j>n*n){
                            b=j;
                            break;
                        }
                        cout <<j<< " ";
                    }
                }
                
            }
            
            cout << 2 <<" ";
            for(ll i =b;i<n*n;i+=2)
            {
                cout << i << " ";
            }
            cout << endl;
            
        }
    }
}