#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int T;
    cin >> T;
    int N, M;
    int a;
    
    vector<vector<int>> matrica1(T, vector <int>(2));
    
    for ( a = 0; a < T; a++)
    { 
        cin >> matrica1[a][0];
        cin >> matrica1[a][1];
    }
    for (a = 0; a < T; a++)
    {
        if (matrica1[a][0] != matrica1[a][1])
        {
            cout << -1 << endl;
        }
        else
        {
            N = matrica1[a][0];
            M = matrica1[a][1];
            vector<vector<int>> matrica2(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;
}