#include <bits/stdc++.h>
using namespace std;

 int T, N, M, n1, m1, br;
 bool ntr=false, mtr=false;

void Nt()
{

}

int main(){

  cin >> T;
  for(int i=1; i<=T; i++)
  {
      cin >> N >> M;
     if(N == M)
     {
         for(int m=1; m<=M; m++)
        {
            br++;
            for(int n=1; n<=N; n++)
            {
                if(n!=N and N%br==0) cout << 0 << " ";
                else if(n!=N and N%br!=0) cout << 1 << " ";
                else if(n==N and N%br==0)cout << 1 <<endl;
                else if(n==N and N%br!=0)cout << 0 <<endl;
            }
        }
     }
     else cout << -1;
  }



  return 0;
}