#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define f first
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,n,m,k;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        cin>>a[i];
        vector<vector<int>>v(n,vector<int>(32,0));
        for(int i=0;i<n;i++)
        {
            int y=a[i];
            k=31;
            while(y!=0)
            {
                v[i][k]=y%2;
                y=y/2;
                k--;
            }
        }
        vector<int>ans;
        ans.push_back(0);
        for(int i=1;i<n;i++)
        {
            
            if((a[i]&a[i-1])==a[i-1])
            ans.push_back(0);
            else
            {
                vector<int>temp;
                for(int k=31;k>=0;k--)
                {
                    if(v[i-1][k]==1)
                    {
                        if(v[i][k]==1)
                        temp.push_back(0);
                        else
                        temp.push_back(1);
                    }
                    else
                    temp.push_back(0);
                }
                int tr=0;
                k=31;
                int sum=0,o=0;
                for(int yu=0;yu<temp.size();yu++)
                {
                    v[i][k]=v[i][k]^temp[yu];
                    sum+=v[i][k]*pow(2,o++);
                    k--;
                    //cout<<temp[yu]<<" ";
                    tr+=temp[yu]*pow(2,yu);
                }
                while(k>=0)
                {
                    sum+=v[i][k]*pow(2,o++);
                    k--;
                }
                a[i]=sum;
                //cout<<sum<<" ";
                //cout<<"\n";
                ans.push_back(tr);
            }
        }
        //cout<<"\n";
        for(int i:ans)
        cout<<i<<" ";
        cout<<"\n";
    }
}
