#include <bits/stdc++.h>

using namespace std;

void resi(){
    int N,M;
    if((!(cin >> N >> M)) == 1)
        return;

    if(N != M){
    cout << -1 << endl;
    return;
    }
    for(int i = 1;i <= N;i++){
        for(int j = 1;j <= N;j++){
              if(j + i >= N+1)
                cout << 1 << " ";
              else
                cout << 0 << " ";
    }
    cout << endl;
    }
    return;
}
int main()
{
    int T;
    cin >> T;
    while((T--) > 0)
        resi();


    return 0;
}