#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 j=0;j<a;j++){
                matrica[a-1][j]=1;
                matrica[0][j]=1;
                matrica[j][b-1]=1;
                matrica[j][0]=1;
                if (j>2) matrica[j][j]=1;
                int r=2;
                while(j-r-1>0){
                    matrica
                }
                cout<<matrica[i][j]<<" ";
            }
            cout<<endl;
        }
    }
    return 0;
}