// cout<<" @gagan2001 "<<endl;
#include <bits/stdc++.h>
using namespace std;

#define pb() push_back()
#define sort_decrease(arr) sort(arr.begin(),arr.end(),greater<ll>()); 
#define p_q       priority_queue<ll>pq
#define p_q_inc   priority_queue < ll , vector<ll> , greater<ll> > pq

typedef long long ll;

template <typename T> T countDigit(T n) { return ( (n==0) ? 1 : floor( log10(n) + 1 ) ) ; }

template <typename T> T GCD(T a,T b) { return ( (b%a==0)? a : GCD(b%a,a) );} 

long long mod_by= 100000000007;
long long binpow(long long a, long long b)
 { a %= mod_by;
  long long res = 1;
   while (b > 0)
   { 
      if (b & 1) 
         res = res * a % mod_by;  
          a = a * a % mod_by; b >>= 1;
   } 
     return res;
   }

bool sortcol( const vector<ll>& v1, const vector<ll>& v2 ) {return v1[0] > v2[0];} 

bool isPrime(ll n)
{
    if (n <= 1) return false;
    if (n <= 3)return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (ll i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0)   return false;
    return true;
}
 

/*-----------Solution--is--here------------*/


void solve()
{
  ll t;
  cin>>t;
  while(t--) 
  {
    ll n;
    cin>>n;
    std::vector<ll> v(n);
    std::vector<ll> ans(n);

    for (int i = 0; i < n; ++i)
    {
       cin>>v[i];
    }
ans[0]=0;

for (int i =1; i < n; ++i)
{
   ll prv_xor = ans[i-1]^v[i-1];
   ll a = ( v[i] & prv_xor  );
   ans[i]= prv_xor ^a;
}



for (int i = 0; i < n; ++i)
{
  cout<<ans[i]<<" ";
}

cout<<endl;

  }

}


// for kick // cout<<"Case #"<<g-t<<": "<< ans <<endl;

int main()
{ 
     ios_base::sync_with_stdio(false); //fast input output
     cin.tie(NULL);
     solve();

    // cout << fixed << setprecision(10) <<ans<<endl;
  return 0;
}