#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,0));
            for (long long i=0;i<a;i++){
                matrica[a-1][i]=1;
                matrica[0][i]=1;
                matrica[i][b-1]=1;
                matrica[i][0]=1;
                if (i!=0 && i!=1 && i!=a-1){
                    matrica[i][i]=1;
                }
            }
            for (long long i=0;i<a;i++){
                for (long long j=0;j<a;j++){
                    cout<<matrica[i][j]<<" ";
                }
                cout<<endl;
            }
        }
    }
    return 0;
}