#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int T, i, j, z, n, m;
    cin >> T;
    vector <int>a;

    for(i = 0; i < T; i++){
        cin >> n >> m;

        if(n != m){
            a.push_back(-1);
        }

        else{
            a.push_back(n);
        }

    }

    for(i = 0; i < T; i++){

        if(a[i] == -1){
            cout << -1 << endl;
        }

        else{
            int mat[a[i]][a[i]];
            for(j = 0; j < a[i]; j++){
                for(z = 0; z < a[i]; z++){
                    if(j == 0 or j == a[i] - 1){
                        mat[j][z] = 1;
                    }
                    else{
                        if(z == 0 or z >= a[i] - j){
                            mat[j][z] = 1;
                        }
                        else{
                            mat[j][z] = 0;
                        }
                    }
                    cout << mat[j][z] << " ";
                }
                cout << endl;
            }
        }
    }
}