#include<bits/stdc++.h>
using namespace std;
#include<vector>
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        vector <int> v;
        for(int i=0;i<n;i++)
        {   
            int k;
            cin >> k;
            v.push_back(k);
        }

        vector <int> ans;
        ans.push_back(0);
        for(int i=1;i<n;i++){
            ans.push_back((v[i-1]^ans[i-1]) & (~v[i]));
        }
        for(int i : ans){
           cout << i << " " ;
        }
        cout << endl;
            
        
    }
}