#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{
            for (long long k=0;k<a;k++){
                vector<int>lista(a,1);
                for (long long m=0;m<a;m++){
                    if (k!=0 && k!=a-1 && m!=0 && m!=a-1 && k+m<=a+1){
                        lista[m]==0;
                    }
                }
                for (long long x=0;x<a;x++){
                    cout<<lista[x]<<" ";
                }
            cout<<endl;
            }
        }
    }
    return 0;
}