#include<bits/stdc++.h>
using namespace std;
int t,n,m,br,k = 2;
int mat[1005][1005];
int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>t;
    while(t--){
        cin>>n>>m;
        if(m == n){
        memset(mat, 0, sizeof(mat));
        for(int i = 1; i <= n; i++){
            for(int j = 1; j<= m; j++){
                    mat[1][j] = 1;
                    mat[i][1] = 1;
                    mat[n][j] = 1;
                    mat[i][n] = 1;
                }
            }

        for(int i = n; i > 1; i--){
                for(k ; k <= m; k++){
                    mat[i][k] = 1;
                }
                br++;
                k = 2;
                k += br;
            }

        for(int i = 1; i <= n; i++){
            for(int j = 1; j<= m; j++){
                    cout<<mat[i][j]<<" ";
                }
                cout<<endl;
            }
            k = 3;
            br = 0;
        }
        else{
            cout<<-1<< endl;
        }
    }

    return 0;
}