#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        int n, m;
        cin >> n >> m;
        if (n != m)
        {
            cout << -1 << "\n";
            continue;
        }
        else
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    if (i == 0 || j == 0 || i == n-1 || j == m-1 || (i+j+2) >= (n+2))
                    {
                        cout << 1 << " ";
                    }
                    else
                    {
                        cout << 0 << " ";
                    }
                }
                cout << "\n";
            }
        }
    }
    return 0;
}