#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define repa(i,a,b) for(ll i = a; i <= b; i++)
#define repd(i,a,b) for(ll i = a; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vl vector<ll>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ld long double
#define nl cout << "\n"
#define MAX 1000000000000
#define all(x) x.begin(),x.end()
//debuging	
#define deb1(n) cout<<n<<" "
#define deb2(a,n) cout<<"a->"<<n<<" "
#define deb3(A,a,b) repa(i,a,b){cout<<A[i]<<" ";}nl
#define deb4(v) repa(i,0,v.size()-1){cout<<v[i]<<" ";}nl
// #define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

void solve(){
	ll n;
	cin >> n;
	vl v(n), ans(n,0);
	repa(i,0,n-1) cin >> v[i];
	if(n == 1){
		cout << 0; nl;
		return;
	}
	ans[0] = 0;
	bitset <32> bst1, bst2;
	repa(i,1,n-1){
		bst1 = v[i-1] ^ ans[i-1];
		bst2 = v[i];
		for(ll j = 0; j <= 30 ; j++){
			if( bst1[j] == 1 && bst2[j] == 0){
				ans[i] += 1<<j;
			}
		}

	}
	repa(i,0,n-1){
		cout << ans[i] << " ";
	}
	nl;
}

int main (){
	IOS;
	#ifndef ONLINE_JUDGE 
	freopen ( "input.txt", "r", stdin );
	freopen ( "output.txt", "w", stdout );
	#endif 

	ll t = 1;
	cin >> t;
	while(t--){
		solve();
	}
  	return 0;
}