#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while (t--){
        int a, b;
        cin >> a >> b;
        if (a != b){
            cout << "-1\n";
            continue;
        }
        for (int i = 0; i < a; i++){
            for (int j = 0; j < a - i - 1; j++){
                cout << "0 ";
            }
            for (int j = a - i - 1; j < a; j++){
                cout << "1 ";
            }
            cout << "\n";
        }
    }
}