#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN=5e5+5;
ll a[MAXN];
int main()
{
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        if(n%2==0)
        {
            ll cnt=n;
            for(int i=n;i>=1;i--)
            {
                for(int j=1;j<i;j++)
                {
                    if(i%2==0&&j==1)
                    {
                        cout<<0<<" ";
                    }
                    else if(j%2==0)
                    {
                        cout<<1<<" ";
                    }
                    else if(j%2==1)
                        cout<<-1<<" ";
                }
            }
            cout<<endl;
        }
        else
        {
            for(int i=n;i>=1;i--)
            {
                for(int j=1;j<i;j++)
                {
                    if(j%2==1)
                        cout<<1<<" ";
                    else cout<<-1<<" ";
                }
            }
            cout<<endl;
        }
    }
}
                                                                                                                                                                                                                                         