/*Author:-Naman Jain (@JainSahab)*/
/*If you are bad then call me your Dad*/
#include<bits/stdc++.h>
using namespace std;

#define fastinput   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long 
#define sortv(l) sort(l.begin(),l.end());
#define sortvr(l) sort(l.begin(),l.end(),greater()<>);
#define sortar(ar,n) sort(ar,ar+n);
#define test ll t;  cin>>t; while(t--)
#define inpn(type,name) type name; cin>>name;
#define make(x,y) make_pair(x,y)
#define print(x) cout<<x<<"\n";
#define loop(name,start,end,step) for(long long int name=start;start<=end;start+=step)
#define inpvect(type,name,n)  type temp; vector<type> name; for(long long int i=0;i<n;i++){cin>>temp; name.push_back(temp); }
#define inparr(type,name,n)  type name[n]; for(long long int i=0;i<n;i++){cin>>name[i];}
#define prinarr(name,n)  for(long long int i=0;i<n;i++){cout<<name[i]<<" ";} cout<<endl;
#define prinvect(name) for(long long int i=0;i<name.size();i++){cout<<name[i]<<" ";} cout<<endl;
#define maxheap priority_queue<int>
#define minheap priority_queue <int, vector<int>, greater<int>> 
#define sumve(name) accumulate(name.begin(),name.end(),0ll)
#define all(name) name.begin(),name.end()
#define sumar(name,n) accumulate(name,name+n,0ll)

int main(){
   fastinput
   vector<ll>power;
   for(auto i=0;i<30;i++){
       power.push_back((long long)pow(2,i));
   }
   test{
    ll n;
    cin>>n;
    vector<ll>a(n);
    for(auto i=0;i<n;i++){
        cin>>a[i];
    }
    vector<ll>ans(1,0);
    for(auto i=1;i<n;i++){
        ll f=0;
        for(auto j:power){
            if((a[i-1]&j)!=0 && (a[i]&j)==0){
                f+=j;
            }
        }
        ans.push_back(f);
        a[i]=a[i]^ans[i];
    }
    prinvect(ans)
     
      
         
       
   }
    
    
    
    
    
}