#include <bits/stdc++.h>
#define ll long long int
#define vll vector<long long int>
using namespace std;
ll MOD = 1e9 + 7;

ll mpow(ll base, ll exp){
    base %= MOD;
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base) % MOD;
        base = ((ll)base * base) % MOD;
        exp >>= 1;
    }
    return result;
}

void solver(){
    ll n;
    cin>>n;
    vll a(n),ans(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
        if(i==0){
            ans[i]=0;
        }
        else{
            if((a[i]&a[i-1])==a[i-1]){
                ans[i]=0;
            }
            else{
                ll val=a[i];
                a[i]|=a[i-1];
                ans[i]=a[i]^val;
            }
        }
    }
    for(ll i=0;i<n;i++){
        cout<<ans[i]<<" ";
    }
    cout<<"\n";
}

int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    
    #endif

    ll t = 1;
    cin>>t;
    while (t--){
        solver();
    }
    return 0;
}
