#define USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <string>




using namespace std;

int main()
{
    int t, n, m, l, s;
    cin >> t;
    for(int i = 1; i <= t;i++)
    {
        cin >> n >> m;
        l = m - 2;
        s = 0;
        if(n != m)
        {
            cout << -1;
        }
        else
        {
        for(int j = 1; j <= m;j++)
        {
            cout << 1 << " ";
        }
        cout << "\n";
        for(int j = 1; j <= n - 2;j++)
        {
            cout << 1 << " ";
            for(int k = 1; k <= l;k++)
            {
                cout << 0 << " ";
            }
            for(int k = 1; k <= s;k++)
            {
                cout << 1 << " ";
            }
            cout << 1;
            l -= 1;
            s += 1;
            cout << "\n";
        }
         for(int j = 1; j <= m;j++)
        {
            cout << 1 << " ";
        }
        }

    }
}