#include <bits/stdc++.h>
#define ll long long int
#define inf 1000000000009
using namespace std; 
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define endl "\n"
#define double long double
#define log log10l


const ll mod = 998244353;
const ll md = mod;
const ll sz = 5000005;

int height = 0;

void dfs(vector<vector<int> > &adj, vector<bool> &visited, int node, int ans=0){
    visited[node] = true;
    height = max(height, ans);

    for(int x : adj[node]){
        if(visited[x]) continue;
        dfs(adj, visited, x, ans+1);
    }
}

int fillArr(vector<vector<int> > &v, bool first){
    if(first)
        v[0][0] = 1;
    else
        v[0][1] = 0;

    int n = v.size();
    int m = v[0].size();

    for(int i=1;i<n;i++){
        if(v[i-1][0] == 1)
            v[i][0] = 0;
        else
            v[i][0] = 1;  

    }

    for(int j=1;j<m;j++){
        if(v[0][j-1] == 1)
            v[0][j] = 0;
        else{
            if(1<n and v[1][j-1] == 1);
            else
                v[0][j] = 1;
        }
    }

    for(int i=1;i<n;i++){
        if(v[i-1][m-1] == 1) {
            v[i][m-1] = 0;
            // continue;
        }

        else if(m-2 >= 0 and v[i-1][m-2] == 1){
            v[i][m-1] = 0;
            // continue;
        }
        else if(i-1 >= 0 and m-2 >= 0 and v[i-1][m-2] == 1)
            continue;
        else if(i >= 0 and m-2 >= 0 and v[i][m-2] == 1) continue;
        else if(i+1 < n and m-2 >= 0 and v[i+1][m-2] == 1) continue;

        else v[i][m-1] = 1;
    }

    for(int j=1;j<m;j++){
        if(v[n-1][j-1] == 1);
            // continue;
        else if(n-2 >= 0 and v[n-2][j-1] == 1);
        else if(n-2 >= 0 and v[n-2][j] == 1) continue;
        else if(n-2 >= 0 and j+1 < m and v[n-2][j+1] == 1) continue;
        else if(j+1 < m and v[n-1][j+1] == 1) continue;
        else
            v[n-1][j] = 1;
    }

    int cnt = 0;

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(v[i][j] == 1) cnt++;
        }
    }
    return cnt;

}

int findAns(vector<int> &v, int x){
    int n = v.size();
    vector<bool> visited(n, false);

    int i = x;

    while(true){
        if(visited[i] == true) return i;
        visited[i] = true;

        i = v[i];
    }
    return 0;
}

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }

    vector<int> ans = {0};

    for(int i=0;i<n-1;i++){
        int tx = v[i]^ans.back();
        if((tx & v[i+1]) == tx){
            ans.push_back(0);
        }
        else{
            // cout<<"Manish"<<endl;
            int prev = v[i+1];
            int temp = tx | prev;
            // cout<<"temp = "<<temp<<en dl;
            temp = temp ^ v[i+1];
            ans.push_back(temp);

        }
    }

    for(int x : ans)
        cout<<x<<" ";
    cout<<endl;
}

int main()
{
    // fast;
    int t;
    cin>>t;
    // t = 1;
    while(t--){
        solve();
    }
    return 0;
}
