#include<bits/stdc++.h>
#define maxn 1000005
#define inf 9999999999999999
#define mod 100003
typedef long long LL;
using namespace std;
LL a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    //freopen("bwxnQAQin.txt","r",stdin);
    LL T;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        if(n&1)
        {
            LL zong=n-1,fuyi=zong/2;
            for(LL i=zong;i>=1;i--)
            {
                for(LL j=1;j<=i-fuyi;j++)cout<<"1 ";
                for(LL j=1;j<=fuyi;j++)cout<<"-1 ";
                if(fuyi)fuyi--;
            }
            cout<<endl;
        }
        else
        {
            LL zong=n-1,ban=zong/2;
            for(LL i=1;i<=zong;i++)
            {
                for(LL j=i;j<=zong;j++)
                {
                    if(j<i+ban)cout<<"1 ";
                    else if(j==i+ban)cout<<"0 ";
                    else cout<<"-1 ";
                }
            }
            cout<<endl;
        }
    }
    return 0;
}
