#include <bits/stdc++.h>
#define ll long long
#pragma GCC optimize("Ofast")

using namespace std;


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


    ll q;
    cin>>q;
    while (q--)
    {
        ll n; cin>>n;
        vector<ll> a(n);
        for (ll i=0; i<n; i++) cin>>a[i];

        cout<<0<<' ';
        ll pr=a[0];
        vector<ll> c(31,0); ll j=30;
        while (pr>0)
            {
                c[j]=pr%2; pr/=2; j--;
            }

        for (ll i=1; i<n; i++)
        {
            vector<ll> t(31,0); j=30;
            ll tek=a[i];
            while (tek>0)
            {
                t[j]=tek%2; tek/=2; j--;
            }

            vector<ll> v(31,0);
            for (ll j=0; j<31; j++)
            {
                if (c[j] && !t[j]) {v[j]=t[j]=1;}
            }

            ll ans=0; ll st=1;
            for (ll j=30; j>=0; j--)
            {
                ans+=v[j]*st; st*=2;
            }
            cout<<ans<<' ';

            c=t;
        }
        cout<<'\n';
    }
}
