#include <bits/stdc++.h>

#define int int64_t

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int tt;
  std::cin >> tt;
  while(tt--) {
    int n, m;
    std::cin >> n >> m;
    if(n != m) {
      std::cout << - 1 << "\n";
      continue;
    }
    for(int i = 1; i <= n; i++) {
      for(int j = 1; j <= m; j++) {
        std::cout << "1 ";
      }
      std::cout << "\n";
    }
  }
  /**
  int N, M;
  std::cin >> N >> M;
  int n = N * M;
  std::vector<std::vector<int>> a(N + 1, std::vector<int>(M + 1));
  std::vector<std::pair<int, int>> par;
  for(int i = 1; i <= N; i++) {
    for(int j = 1; j <= M; j++) {
      par.push_back({i, j});
    }
  }
  for(int mask = 0; mask < (1LL << n); mask++) {
    std::vector<int> r(N + 1), c(M + 1);
    for(int i = 0; i < n; i++) {
      if(mask & (1LL << i)) {
        r[par[i].first] += 1;
        c[par[i].second] += 1;
        a[par[i].first][par[i].second] = 1;
      }
    }
    int ok = 1;
    for(int i = 1; i <= N; i++) {
      ok &= (r[i] > 0 && r[i] % i == 0);
    }
    for(int i = 1; i <= M; i++) {
      ok &= (c[i] > 0 && c[i] % i == 0);
    }
    if(ok) {
      for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= M; j++) {
          std::cout << a[i][j] << " ";
          a[i][j] = 0;
        }
        std::cout << "\n";
      }
      std::cout << "\n";
      return 0;
    }
  }**/
}

/**



**/