#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define Sort(v)         sort(v.begin(),v.end())
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    Fast
    ll t,i,j,k;cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        if(n==1)cout<<1<<endl;else if(n==2)cout<<-1<<endl;
        else{
        ll x=n*n;
        if(x%2!=0){
        for(i=1;i<=x;i+=2)cout<<i<<" ";
        for(i=2;i<x;i+=2)cout<<i<<" ";
        }
        else if(x%2==0){
        for(i=1;i<x;i+=2)cout<<i<<" ";
        for(i=2;i<=x;i+=2)cout<<i<<" ";

        }
        }

    }


}
