#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve()
{
   
}
 
int main(){
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
   ll t;
   cin>>t;
   while(t--)
   {
    //solve();
     ll n;
     cin>>n;
     ll a[n];
     for(ll i=0;i<n;i++)
     cin>>a[i];

     vector<ll>v;
     ll p=a[0];
     v.push_back(0);
     for(ll i=1;i<n;i++)
     {
         ll g1=p,g2=a[i];

         ll j=0;

         ll a1[32]={0};
         ll a2[32]={0};
         while(g1>0)
         {
             if(g1%2==1)
              a1[j]=1;
              g1/=2;
              j++;
         }
         j=0;
          while(g2>0)
         {
             if(g2%2==1)
              a2[j]=1;
              g2/=2;
              j++;
         }
         ll p5=0;
         for(ll j=0;j<31;j++)
         {
             if(a1[j]==1&&a2[j]==0)
             {
                 p5+=(ll)(pow(2,j)+0.5);
             }
         }
         p=a[i]^p5;
         v.push_back(p5);
     }
     for(ll i=0;i<v.size();i++)
     cout<<v[i]<<" ";
     cout<<endl;
   }

 
}