#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define deb(x) cout<<#x<<'='<<x<<endl
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    IOS;
    int t;cin>>t;
    while(t--){
        int n;cin>>n;
        int a[n];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        vi ans(n);
        ans[0]=0;
        for(int i=1;i<n;i++){
            int c=a[i-1]^ans[i-1];
            ans[i]=c&(~a[i]);
        }
        for(auto i:ans)
            cout<<i<<" ";
        cout<<endl;
    }

    return 0;
}