#include<bits/stdc++.h>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
    cout.tie(0);
	int t, i, r, k, n, m, a[10000][10000];
	cin >> t;
    bool moguce;
	for(i = 1; i <= t; i++){
		cin >> n >> m;
        moguce = true;

        if(n == m) moguce = true;
        //if((n % 2 == 0 && m % 2 != 0) || (n%2 != 0 && m % 2 == 0))moguce = false;
        else moguce = false;
		
		int desno = m;
		
		if(moguce == true){
			for(r = 1; r <= n; r++){
				for(k = 1; k <= m; k++){
					if(r == 1 || r == n || k == 1 || k == m || desno == 1) cout << "1" << " ";
					else if(k <= desno) cout << "0" << " ";
					else cout << "1" << " ";
				}
				desno--;
			}
		}
		else{
			cout << "-1" << "\n";
		}
			
	}
	return 0;
}