#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a;
    int b;
    for (int i=0;i<n;i++){
        cin>>a>>b;
        if (a!=b){
            cout<<-1<<endl;
        }
        else{
            vector<vector<int>>matrica(a,vector<int>(b,0));
            for (int 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 (int i=0;i<a;i++){
                for (int j=0;j<a;j++){
                    cout<<matrica[i][j]<<" ";
                }
                cout<<endl;
            }
        }
    }
    return 0;
}