#include <iostream>
using namespace std;
int t,n;
int main(){
    cin>>t;
    while(t--){
        cin>>n;
        if(n%2){
            for(int i=1;i<=n-1;i++){
                if(i%2){
                    for(int j=1;j<=n-i;j++){
                        if(j<=(n-i)/2){
                            cout<<"1 ";
                        }else{
                            cout<<"-1 ";
                        }
                    }
                }else{
                    for(int j=1;j<=n-i;j++){
                        if(j<=(n-i)/2){
                            cout<<"-1 ";
                        }else{
                            cout<<"1 ";
                        }
                    }
                }
            }
            cout<<endl;
        }else{
            for(int i=1;i<=n-1;i++){
                if(i%2){
                    for(int j=1;j<=n-i;j++){
                        if((n-i)%2){
                            if(j==1) cout<<"0 ";
                            else if(j<=(n-i+1)/2) cout<<"1 ";
                            else cout<<"-1 ";
                        }else{
                            if(j<=(n-i)/2) cout<<"1 ";
                            else cout<<"-1 ";
                        }
                    }
                }else{
                    for(int j=1;j<=n-i;j++){
                        if((n-i)%2){
                            if(j==1) cout<<"0 ";
                            else if(j<=(n-i+1)/2) cout<<"-1 ";
                            else cout<<"1 ";
                        }else{
                            if(j<=(n-i)/2) cout<<"-1 ";
                            else cout<<"1 ";
                        }
                    }
                }
            }
            cout<<endl;
        }
    }
}