#include<bits/stdc++.h>
using namespace std;
#define iso ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll MOD = 1011001110001111ll;
#define pb push_back
#define clr(x,n) memset((x), n, sizeof(x))
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_tree;*/
ll ans[105][105];

void solve()
{
    ll n;
    cin >> n;
    vector<ll> v;
    clr(ans, 0);
    ll c = n*(n-1)/2;
    ll len = n-1;
    ll cnt = c/n;
    ll x = cnt;
    for(ll i = 1; i < n; i++)
    {
        //cout << cnt << "\n";
        for(ll j = 1; j <= min(n-i,cnt); j++)
        {
            //cout << 1 << " ";
            ans[i][j] = 1;
        }
        

        for(ll j = len; j> len-x; j--)
        {
            //cout << "-1 ";
            ans[i][j] = -1;
        }
        x--;
        len--;
        //cout << "\n";
    }
    for(ll i = 1; i < n; i++)
    {
        for(ll j = 1; j < n; j++)
        {
            if(i+j <= n)
            {
                v.pb(ans[i][j]);
                //cout << ans[i][j] << " ";
            }
        
        }
        //cout << "\n";
    }
    for(auto el: v)
        cout << el << " ";
    cout << "\n";
    

}
int main()
{
    
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    //factorial();
    iso;
    ll t;
    t = 1;
    cin >> t;
    
    while(t--)
    {
        solve();
    }
    return 0;
}
