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

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int t;
    cin>>t;
    while (t--)
    {
        int n,m;
        cin>>n>>m;
        int a[n][m];
        if (n == m)
        {
            for (int i = 0; i<n; i++)
            {
                for (int j = 0; j<m; j++)
                { int brojac = i;
                    if ( i == 0 || i == n-1){cout<<1;}
                    else if (j == 0 || j == n-1){cout<<1;}
                    else if (brojac >=2 && j>=n-i){cout<<1; brojac--;}
                    else{cout<<0;}

                }
                    cout<<'\n';
                }


        }
            else {cout<<-1<<'\n';}
        }
    }