#include <bits/stdc++.h>   using namespace std;   #define ll long long   #define deb(x) cout << #x <<  =  << x << endl   #define deb2(x, y) cout << #x <<  =  << x <<  ,  << #y <<  =  << y << endl   #define nl   n    void solve()   {       int n;       cin >> n;       int arr[n][n];       int x = 1;       for(int i=0;i<n;i++){           for(int j=0;j<n;j++){               if(i==j){                   arr[i][j]=x;                   x++;               }           }       }       for (int k = 1; k <= 2 * n - 2; k++)       {           for (int i = 0; i < n; i++)           {               for (int j = 0; j < n; j++)               {                   if(i!=j){                       if (i + j == k)                   {                       arr[i][j] = x;                       x++;                   }                   }               }           }       }       if (n == 1)       {           cout << 1 <<   n ;           return;       }       else if (n == 2)       {           cout << -1 <<   n ;       }       else       {           for (int i = 0; i < n; i++)           {               for (int j = 0; j < n; j++)               {                   cout << arr[i][j] <<    ;               }               cout <<   n ;           }       }   }   int main()   {       ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);       srand(chrono::high_resolution_clock::now().time_since_epoch().count());       int t;       cin >> t;       while (t--)       {           solve();       }       return 0;   }