/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;
    while (t--){
        int n;
        cin >> n;
        
        if (n == 2){
            cout << -1 << endl;
            continue;
        }
        
        int count1 = 1; int count2 = (n * n + 1) / 2 + 1;
        int a[n][n];
        
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                if ((i + j) % 2 == 0){
                    a[i][j] = count1; count1++;
                } else {
                    a[i][j] = count2; count2++;
                }
            }
        }
        
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                cout << a[i][j] << " ";
            } cout << endl;
        }
    }

    return 0;
}
