#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    int k=0;
    while(k<t)
    {
        int n;
        cin>>n;
        if(n==1)
        {
            cout<<"1\n";
            k++;
            continue;
        }
        if(n==2)
        {
            cout<<"-1\n";
            k++;
            continue;
        }
        else 
        {
            int a[n][n];
            int ctr=1;
            for(int i=0;i<n;i++)
            {
                int index=i%2;
                for(int j=index;j<n;j=j+2)
                {
                    a[i][j]=ctr++;
                }
            }

            for(int i=0;i<n;i++)
            {
                int index;
                if(i%2==0)
                {
                    index=1;
                }
                else
                {
                    index=0;
                }
                for(int j=index;j<n;j=j+2)
                {
                    a[i][j]=ctr++;
                }

            }
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<n;j++)
                {
                    cout<<a[i][j]<<" ";
                }
                cout<<"\n";
            }
        }
        k++;
    }
}