#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int g = n*2;
    int niz[g];
    for(int i=0;i<g;i++){
        cin >> niz[i];}
    int i=n;
    int b=1;
    while(i>0){
        int N=niz[g-1-b];
        int M=niz[g-b];
        cout << N << endl;
        cout << M << endl;
        if(N!=M){
            cout << -1;
        }
        if(N==M) {
            for(int x=0;x<N;x++){
                cout << "\n";
                for(int y=0;y<M;y++){
                    if(x==0 || y==0 || x==N-1 || y==M-1 || (x==3 && y==4)|| (x==4 && y==3) || (x>3 &&y>3 && x==y)){
                        cout << 1 << " ";
                    }
                    else
                        cout << 0 << " ";


                }
            }

        }
        b=b+2;
        i--;
    }

    return 0;
}