#include<bits/stdc++.h>
using namespace std;
int t, n, m, br;
int mat[1005][1005];


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> t;
    for(int i = 1; i <= t; i++){
        cin >> n >> m;
        memset(mat, 0, sizeof(mat));
        if(n == m){
           for(int j = m; j >= 1; j--){
               mat[n][j] = 1;
           }
           /*for(int j = 2; j <= m; j++){
               mat[n-1][j] = 1;
           }
           for(int j = 3; j <= m; j++){
               mat[n-2][j] = 1;
           }*/
           /*for(int i = n; i >= 1; i--){
               mat[i][m] = 1;
           }*/
           for(int i = 1; i <= n; i++){
               for(int j= i+1; j <= m; j++){
                   mat[n-i][j] = 1;
               }
           }
           for(int i = 1; i <= n; i++){
               for(int j = 1; j <= n; j++){
                  cout << mat[i][j] << " ";
               }
              cout << endl;
           }
        }
        else {
            cout << -1 << endl;
        }
    }
    return 0;
}