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

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

    int T;
    cin>>T;

    while(T--)
    {
        long long N, M;
        cin>>N>>M;



        if(N!=M)
        {
            cout<<-1<<"\n";

            continue;
        }



        for (int i=1;i<=N;i++)
            {
            for (int j=1; j<=M; j++)
            {
                if(j >1)
                cout<< " ";
                cout<<(i+j>=N+1 ? 1 : 0);
            }
            cout<< "\n";
        }
    }

    return 0;
}