#include <iostream>

using namespace std;

int main()
{
    int t;
    cin >> t;

    for(int i = 0; i < t; i++)
    {
        int n, m;
        cin >> n >> m;

        if(n != m) cout << -1 << endl;
        else
        {
            for(int x = 0; x < m; x++)
            {
                for(int y = 0; y < n; y++)
                {
                    if(y == 0 || x == 0 || x == n - 1 || y == n - 1) cout << 1 << " ";
                    else if(x + y >= n) cout << 1 << " ";
                    else cout << 0 << " ";
                }

                cout << endl;
            }
        }
    }

    return 0;
}