#include <iostream>

using namespace std;

int main()
{
    int t;
    cin>>t;
    for(int z = 0; z < t; z++)
    {
        int n;
        int m;
        cin>>n>>m;
        int a[n][m];
        int kol[n];
        int red[n];
        for(int i  = 0; i < n; i ++)
        {
            kol[i] = 0;
            red[i] = 0;
        }
        if(n != m)
            cout<<"-1";
        else
        {
            int  k =0;
            int  pom = -1;
            int i =  n-1;
            for(int  i =  n-1;  k <  n-2; i = i + pom*(i-k))
            {
                for(int j = n-1; j > -1; j --)
                {
                    pom = -1*pom;
                    k++;
                    if(i == 0 || j  ==  0 || j == n-1 ||  i == n-1)
                    {
                        a[i][j] =  1;
                        kol[j] ++;
                        red[i] ++;
                    }
                    else if(j+1%kol[j]!=0 &&  i+1%red[i]!=0)
                        {
                            a[i][j] = 1;
                            kol[j] ++;
                            red[i] ++;
                        }
                    else
                        a[i][j]=0;

                }
            }
            for(int j = 0;  j < n; j ++)
            {
                for(int ka = 0; ka < m; ka ++)
                {
                    cout<<a[j][ka]<<' ';
                }
                cout<<endl;
            }
        }

    }
    return 0;
}