#include<bits/stdc++.h>
using namespace std;
 
signed main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<int> a(n,0);
        for(int i=0;i<n;i++)
        {
            int x;
            cin>>x;
            a[i]=x;
        }
        vector<int> ans(n,0);
        for(int i=0;i<n-1;i++)
        {
            int k =a[i]&a[i+1];
            //cout<<a[i]<<endl;
            if(k!=a[i])
            {
                int x = a[i]|a[i+1];
                int y = a[i+1]^x;
                ans[i+1]=y;
                a[i+1]=x;
            }
            
        }
        for(int i=0;i<n;i++)
            cout<<ans[i]<<" ";
        cout<<endl;
        
            
        
 
    }
}