#include <iostream>   #include <iosfwd>   #include <iomanip>   #include <cstdio>   #include <cstring>   #include <cstdlib>   #include <ctime>   #include <cmath>   #include <cassert>   #include <cctype>   #include <climits>   #include <vector>   #include <bitset>   #include <set>   #include <queue>   #include <math.h>   #include <stack>   #include <map>   #include <deque>   #include <string>   #include <list>   #include <iterator>   #include <sstream>   #include <complex>   #include <fstream>   #include <functional>   #include <numeric>   #include <utility>   #include <algorithm>   #include <assert.h>   #include <unordered_map>   #include<ctime>   #include <chrono>   #pragma GCC optimize ( -O3 )   using namespace std;      #define tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);   #define toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);   #define ll long long int   #define pii pair <ll , ll >   #define pb push_back   #define all(s) s.begin(),s.end()   ll gcd(ll a, ll b) { if (a == 0) return b; return b == 0 ? a : gcd(b, a % b);}   #define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(),  , ,    ); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr <<   n ; }   void err(istream_iterator<string> it) {}   template<typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) { cerr <<  [   << *it <<   =   << a <<   ] ; err(++it, args...);}      /**************************************************************************/   const int x4[] = {1, -1, 0, 0};   const int y4[] = {0, 0, 1, -1};   const int x8[] = {1, 1, 1, -1, -1, -1, 0, 0};   const int y8[] = {1, 0, -1, 1, 0, -1, 1, -1};   /***************************************************************************/   const ll MOD = 1e9 + 7;   const ll MOD2 = 998244353;   const ll INF = 9223372036854775800;   const long double PI = 3.141592653589793;   const int PRECISION = 10;   /***************************************************************************/   const int DIGITSIZE = 18;   const int MAXN = 100001;   const int LOGN = 22;   const int MAXBIT = 62;   /***************************************************************************/   const bool take_test_case = 1;   const bool print_case_no = 0;   /****************************************************************************/      void getac(int T) {    int n;    cin >> n;    if (n == 2) {     cout << -1 <<   n ;     return;    }    int curr = 1;    int sq = n * n;    for (int i = 0; i < n; i++) {     for (int i = 0; i < n; i++) {      cout << curr <<    ;      curr += 2;      if (curr > sq) {       curr -= sq - (n % 2 == 0);      }     }     cout <<   n ;    }      }   int  main()   {   #ifndef ONLINE_JUDGE    freopen( input.txt ,  r , stdin);    freopen( output.txt ,  w , stdout);    freopen( error.txt ,  w , stderr);   #endif    ios_base::sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);    cerr.tie(NULL);    auto start_time = std::chrono::high_resolution_clock::now();       int test_cases = 1;    if (take_test_case) cin >> test_cases;    for (int test_case_no = 1; test_case_no <= test_cases; test_case_no++) {     if (print_case_no)      cout <<  Case #  << test_case_no <<  :  ;     getac(test_case_no);    }    cerr <<  Time elapsed   << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start_time).count();    return 0;   }