#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n;
    cin>>n;
    long long a;
    long long b;
    for (long long i=0;i<n;i++){
        cin>>a>>b;
        if (a!=b){
            cout<<-1<<endl;
        }
        else{
            vector<vector<long long>>matrica(a,vector<long long>(b,1));
            for (long long j=2;j<a;j++){
                long long y=a+1-j;
                while (y!=1){
                    matrica[y][j];
                    y--;
                }
            }
            for (long long m=0;m<a;m++){
                for (long long n=0;n<a;n++){
                    cout<<matrica[m][n]<<" ";
                }
                cout<<endl;
            }
        }
    }
    return 0;
}