#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
using namespace std;
#define int long long

const int pow2 = 1073741824;

void loop() {
    int n;
    cin >> n;
    vector<int> x(n);
    for (auto& i : x) {
        cin >> i;
    }
    vector<int> y(n);
    //y[0] = 0;
    for (int i = 1; i < n; i++) {
        int prev = (x[i - 1] ^ y[i - 1]);
        int m = 1;
        int now = 0;
        while (m <= pow2) {
            if ((prev & m) && !(x[i] & m)) {
                now += m;
            }
            m *= 2;
        }
        y[i] = now;
    }
    for (int i : y) {
        cout << i << ' ';
    }
    cout << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        loop();
    }
    return 0;
}
