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

 int T, N, M, br, x;

void Nt()
{
   for(int m=1; m<=M; m++)
   {
      x=0;
      br++;
      for(int n=1; n<=N; n++)
      {
         if(n!=N and br==x)
         {
            cout << 0 << " ";
         }
         else if(n!=N and br!=x)
         {
            x++;
            cout << 1 << " ";
         }
         if(n==N and br==x)
         {
            cout << 0 <<endl;
         }
         else if(n==N and br!=x)
         {
             x++;
             cout << 1<<endl;
         }
      }
   }
}

int main(){

  cin >> T;
  for(int i=1; i<=T; i++)
  {
      cin >> N >> M;
     if(N%2 == M%2)
     {
         Nt();
     }
     else cout << -1;
  }



  return 0;
}