#include <iostream>

using namespace std;

int main()
{
    int T;
    cin>>T;
    for(int k=0;k<T;k++){
        long M,N;
        long nule = M - 2;
        cin>>M>>N;
        if(M==N){
            for (int i = 0; i < M; i++)
                    {
                        long tr = nule - i + 1;
                        if (i == 0 || i == M - 1)
                        {
                            for (int j = 0; j < N; j++)
                            {
                                if (j != N - 1)
                                {
                                    cout<<"1 ";
                                }
                                else
                                {
                                    cout<<"1";
                                }
                            }
                            cout<<endl;
                        }
                        else
                        {
                            for (int j = 0; j < N; j++)
                            {

                                if (j == 0)
                                {
                                    cout<<"1 ";
                                }
                                else if (j == N - 1)
                                {
                                    cout<<"1";
                                }
                                else if (tr > 0)
                                {
                                    cout<<"0 ";
                                    tr--;
                                }
                                else
                                {
                                    cout<<"1 ";
                                }
                            }
                            cout<<endl;
                        }
                    }
                }
                else
                {
                    cout<<"-1";
                }
        }
    }

}