#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        if (n == 2) {
            cout << "-1\n";
            continue;
        }
        int cnt = 1;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                cout << cnt << ' ';
                cnt += 2;
                if (cnt > n * n) cnt = 2;
            }
            cout << '\n';
        }
    }
    return 0;
}

