#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
ll fun(ll a,ll b){
	return (a&(~b));
}
void solve(){
	ll n;
	cin>>n;
	ll a[n],ans[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	ans[0]=0;
	for(int i=1;i<n;i++){
		ans[i]=fun(ans[i-1]^a[i-1],a[i]);
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;while(t--){solve();}
}