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

#define ff first
#define ss second
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define ins insert
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define rep(i, n) for(i = 0; i < n; i++)
#define mod 1000000007
#define pi 3.141592653589793238460
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


signed main() {
	fast;
	int TC, i, j;
	TC = 1;
	cin >> TC;
	while (TC--) {
		ll n, k, m;
		cin >> n;

		vector<int> a(n), b(n), c(n);
		rep(i, n) cin >> a[i];
		c[0] = a[0];
		for (i = 1; i < n; i++) {
			b[i] = a[i] ^ (a[i] | c[i - 1]);
			c[i] = a[i] ^ b[i];
		}
		for (i = 0; i < n; i++)
			cout << b[i] << " ";
		cout << "\n";
	}
}


