#include<iostream>
#include<sstream>
#include<cstdlib>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef vector<int>VI; typedef vector<VI>VVI;
typedef vector<string>VS;
typedef pair<int, int>PII;
#define FOR(i,n) for((i)=0;(i)<(n);(i)++)
#define BE(a) ((a).begin()),((a).end())
#define SI(a) ((a).size())
#define PB push_back

int t, n, m, i, j, k, x;
int a[105][105];

int main()
{
	cin >> t;
	for (; t > 0; t--)
	{
		cin >> n;
		k = 1;
		FOR(i, n) 
		{
			int x = 0;
			FOR(j, i + 1)
			{
				a[j][n - 1 - i + j] = k;
				k++;
				x++;
			}
			k += x;
		}
		k = 2;
		FOR(i, n - 1)
		{
			FOR(j, i + 1)
			{
				a[n - 1 - (i - j)][j] = k;
				k++;
			}
			k += i + 2;
		}
		if (n == 2) cout << -1 << endl;
		else
		{
			FOR(i, n)
			{
				FOR(j, n) cout << a[i][j] << " ";
				cout << endl;
			}
		}
	}
	return 0;
}