#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t, n, m;
    cin >> t;
    vector<pair<int, int>> nm(t);
    for(int i = 0; i < t; i++)
    {
        cin >> n >> m;
        nm[i] = make_pair(n, m);
    }
    for(auto x:nm)
    {
        if(x.first != x.second)
        {
            cout << -1 << "\n";
            continue;
        }

        n = x.first;
        for(int i = 0; i < n; i++)
        {
            cout << 1;
            int j;
            if(i == 0 || i == n-1)
                j = 0;
            else
                j = n - 1 - i;
            for(int k = 0; k < j; k++)
                cout << " " << 0;
            for(int k = 0; k < n - j - 1; k++)
                cout << " " << 1;
            cout << "\n";
        }
        cout << "\n";
    }
    return 0;
}