#include <iostream>
using namespace std;

int main() 
{
  int t, n, m, br; 
  cin>>t;
  int i, j, g, x;
  float z;
  for(i=0;i<t;i++)
  {
    cin>>n>>m;
    if(m==n)
    {
      z=m-2;
      br=1;
      for(j=0;j<n;j++)
      {
        if(j==0 or j==m-1)
        {
          for(g=0;g<m;g++)
          {
            cout<<"1 ";
          }
        }
        else
        {
          cout<<"1 ";
          if(z==n-2)
          {
            for(x=0;x<z;x++)
            {
              cout<<"0 ";
            }
          }
          else
          {
            for(x=0;x<z-br;x++)
            {
              cout<<"0 ";
            }
            for(x=1;x<br;x++)
            {
              cout<<"1 ";
            }
          }
          cout<<"1 ";
          z=z+0.001;
          br=br+1;
        }
        cout<<endl;
      }
    }
    else
    {
      cout<<"-1"<<endl;
    }
  }
  return 0;
}