

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef set<int> si;
typedef set<ll> sl;
typedef vector<string> vs;
typedef vector<char>vc;

//lower_bound returns an iterator pointing to the first element in the range [first,last) which has a value not less than ‘val’.
//upper_bound returns an iterator pointing to the first element in the range [first,last) which has a value greater than ‘val’.
#define in(v,n) for(ll i=0;i<n;i++)cin>>v[i]
#define inp(v,n) for(ll i=0;i<n;i++)cin>>v[i].first>>v[i].second
#define banao(x,y) memset(x,y,sizeof(x));
#define PI (2*acos(0.0))
#define pb push_back
#define show(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << endl;
#define showpair(v) for(int i = 0; i < v.size(); i++) cout << v[i].first << " " << v[i].second << endl;
#define ff first
#define ss second
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define forn(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define forr(i,e) for(i=e;i>=0;i--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sortn(v) sort(all(v))
#define sortr(v) sort(rall(v))
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
//bool cmp(pll a,pll b)
//return a.ff>b.ff;

void solve()
{
    ll n;
    cin>>n;
    ll a[n+1][n+1];
    ll l;
    if(n%2)
    {
        l=0;
        for(ll i=1; i<=n; i++)
        {

            for(ll j=i+1; j<=n; j++)
            {
                if(l%2==0)
                {
                    a[i][j]=1;
                    a[j][i]=-1;
                }
                else
                {
                    a[i][j]=-1;
                    a[j][i]=1;
                }
                l++;
            }
        }
    }
    else
    {
        l=0;
        for(ll i=1; i<=n; i+=2)
        {
            a[i][i+1]=0;
            a[i+1][i]=0;

            for(ll j=i+2; j<=n; j++)
            {
                if(l%2==0)
                {
                    a[i][j]=1;
                    a[j][i]=-1;
                }
                else
                {
                    a[i][j]=-1;
                    a[j][i]=1;
                }
                l++;
            }
        }
        for(ll i=2; i<=n; i+=2)
        {
            for(ll j=i+1; j<=n; j++)
            {
                if(a[i-1][j]==1)
                {
                    a[i][j]=-1;
                    a[j][i]=1;
                }
                else if(a[i-1][j]==-1)
                {
                    a[i][j]=1;
                    a[j][i]=-1;
                }

            }
        }
    }
    /*for(ll i=1; i<=n; i++)
    {
        for(ll j=1; j<=n; j++)
        {
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }*/
    for(ll i=1; i<=n; i++)
    {
        for(ll j=i+1; j<=n; j++)
            cout<<a[i][j]<<" ";
    }
    cout<<endl;
    return ;
}
int main()
{
    fast;
    ll t;
    cin>>t;
    while(t--)
        solve();
    return 0;
}
