#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int T;
    int N, M;
    cin >> T;
    while(T--){
        cin >> N >> M;
        if(N != M){
            cout << -1;
            continue;
        }

        for(int i = 0; i < N; i++){
            for(int j = 0; j < M; j++){
                if(i == 0 || j == 0 || i == N - 1 || j == M - 1 || i + j > N - 1){
                    cout << 1;
                }
                else cout << 0;
            }
            cout << '\n';
        }
    }
}