#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int T;
    cin >> T;
    int N, M;
    for (int i = 0; i < T; i++)
    {
        cin >> N >> M;
        if (M != N)
        {
            cout << -1 << endl;
        }
        else
        {
            vector<vector<int>> matrica(N, vector <int>(M));
            for (int i = 1; i <= M; i++)
            {
                for (int j = 1; j <= N; j++)
                {
                    if (j == 1 || i == 1 || i == M || j == N)
                    {
                        cout << "1 ";
                    }
                    else 
                    {
                        cout << "0 ";
                    } 
                }
                cout << endl;
            }
        }
    }
    return 0;
}