#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin>>t;
    for (int j=0; j<t; j++) {
        int n,m;
        cin>>n>>m;
        if (n==1 || m==1) {
            cout<<-1<<endl;
        }
        else if (n!=m){
            cout<<-1<<endl;
        }
        else {
            for (int i=1; i<=n; i++) {
                for (int o=1; o<=n; o++) {
                        if (o<=n-i) {
                            cout<<0<<" ";
                        }
                        else {
                            cout<<1<<" ";
                        }
                }
                cout<<endl;
            }
        }
    }
}