#include<iostream>
#include<algorithm>
#include<vector>
 
using namespace std;
typedef long long ll;
void solve()
{
 
    int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
   cin>>a[i];
   if(n==1)
   {
   	cout<<0<<endl;
   	return;
    }
    bool flag=0;
    for(int i=0;i<n-1;i++)
    {
        if((a[i]&a[i+1])!=a[i])
        {
            flag=1;
            break;
        }
    }
    if(flag==0)
    {
        for(int i=0;i<n;i++)
        cout<<0<<" ";
        cout<<"\n";
        return;
    }
 
    vector<int>ans(n);
 
    ans[0]=0;
 
    for(int i=1;i<n;i++)
    {
        ll x=a[i-1]^ans[i-1];
        ll y=a[i];
        ll sum=0;
        ll val=1;
        while(x)
        {
            ll a1=(x&1);
            ll a2=(y&1);
            if(a1!=a2)
            {
                if(a1==1 && a2==0)
                sum+=val;
            }
            x>>=1;
            y>>=1;
            val<<=1;
        }
        ans[i]=sum;
    }
    for(int i=0;i<n;i++)
    cout<<ans[i]<<" ";
    cout<<"\n";
}
 
 
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}