#include <bits/stdc++.h>
using namespace std;
#define ll long long

ll mod = 1e9 + 7;
//observations



void solve(){
   
  ll n ; cin>> n; 
  vector<ll> v ; 
  for(ll i=0 ;i< n;i++) { ll m ; cin >> m ; v.push_back(m);}

  vector<ll> ans ; ans.push_back(0);
  vector<ll> pows; ll num = 1;
  for(ll i=0 ; i<34 ;i++) {pows.push_back(num) ; num= num*2 ;}

  for(ll i=1 ; i<n;i++) {
     ll prev = v[i-1] ; ll now = v[i] ;
     ll adder =0 ;
     for(ll i=0;i<31;i++){
        //cout << i << " " << (prev&(1<<i)) << endl;
          if( ((prev&(1<<i)) !=0) && ((now&(1<<i)) ==0)){
              adder += pows[i] ;
          }
     }
     v[i] = v[i] + adder ;
     ans.push_back(adder) ;
  }

for(auto g : ans) { cout << g << " ";} cout << endl;
 }
 
 

 
int main(){
   ios_base::sync_with_stdio(false);
  cin.tie(NULL) ;  cout.tie(NULL);
    ll t ; cin>> t ;  
    while(t--){ solve();

   
    }
 
 
}