#include<bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<fstream>
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define For(i,n) for(long long i=0; i<n; i++)
#define FOR(i,f,l) for(long long i=f; i<l; i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007

void solve(){
  ll n;
  cin>>n;
  vector<ll> v(n),ans;
  For(i,n){
    cin>>v[i];
  }
  if(n==1){
    cout<<0<<endl;
  }
  else{
    ans.pb(0);
    for(ll i=1; i<n; i++){
        if((v[i]&v[i-1])==v[i-1]){
            ans.pb(0);
        }
        else{
            ll temp = v[i]^v[i-1];
            temp = temp&v[i-1];
          //  cout<<i<<endl;
           // cout<<temp<<" "<<1<<endl;
            ans.pb(temp);
            v[i] = v[i]+temp;
          //  cout<<v[i]<<" "<<2<<endl;
        }
    }
    for(ll i=0; i<n; i++){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
  }

}


int main(){
   fastio
   ll t;
   cin>>t;
   while(t--){
     solve();
   }
}

