#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,arr[200005],n,prev,elem,val1,val2;
    cin>>t;
    while(t--)
    {
        cin>>n;
        // cout<<"test = "<<(1<<1)<<'\n';
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
        }
        prev = arr[0];
        cout<<"0 ";
        for(int i=1;i<n;i++)
        {
            elem = 0;
            ll vari;
            for(ll j=0;j<=31;j++)
            {
                if((prev&(elem^arr[i]))==prev)
                {
                    // cout<<"prev = "<<prev<<" xoer = "<<(elem^arr[i])<<' '<<"elem = "<<elem<<" arr[i] = "<<arr[i]<<'\n';
                    cout<<elem<<' ';
                    prev = (elem^arr[i]);
                    break;
                }
                vari = (1<<j);
                val1 = prev&vari;
                val2 = arr[i]&vari;
                if(val1!=val2)
                {
                    
                    if(val1!=0)
                    {
                        elem += vari;
                        // cout<<"enter\n";
                    }
                    
                }
            }
        }
        cout<<'\n';
    }
    return 0;
}