#include <bits/stdc++.h>
using namespace std;
int T, n, temp;
vector<int> X, ans;
int main()
{
#ifdef __DEBUG__
    freopen("../testin.txt", "r", stdin);
#endif

    scanf("%d", &T);
    while (T--) {
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) {
            scanf("%d", &temp);
            X.emplace_back(temp);
        }
        ans.emplace_back(0);
        for (int i = 1; i < (int)X.size(); i++) {
            int cnt = 0, ret = 0;
            while (X[i - 1] >= (1 << cnt)) {
                if ((X[i - 1] & (1 << cnt)) != 0 && (X[i] & (1 << cnt)) == 0)
                    ret += (1 << cnt);
                cnt++;
            }
            X[i] ^= ret;
            ans.emplace_back(ret);
        }
        for (auto& i : ans) {
            printf("%d ", i);
        }
        printf("\n");
        ans.clear();
        X.clear();
    }

    return 0;
}