//Abhinav garg


#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define loop(i,a,n) for(int i=a;i<=n;i++)
#define rev(j,a,n)  for(int j=a;j>=n;j--)
#define pb push_back
#define vi vector
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pr pair<int, int>
#define ff first
#define ss second
#define ump unordered_map
#define mod 1000000007
using namespace std;
inline void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("inp.txt", "r", stdin);
freopen("op.txt", "w", stdout);
#endif
}



void solve(){
    int n; cin>>n;
    vi<int> a(n);
    loop(i,1,n){
        cin>>a[i-1];
    }
    vi<int> res(n);
    res[0]=0;
    loop(i,1,n-1){
        int b=res[i-1]^a[i-1];
        res[i]=(b&(~a[i]));   
    }
    for(int i:res){
        cout<<i<<' ';
    }
    cout<<"\n";

}


int32_t main(int argc,char const *arg[]){
    fastio();
    int t; cin>>t;
    //prime();
    
    while(t--){
        solve();
    }


    return 0;
}