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

#ifdef Asterix
#include "debug.h"
#else
#define dbg(...)
#endif

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int t;
	cin >> t;

	while(t--) {
		int n;
		cin >> n;
		
		vector<int> a(n);
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}

		int prev = a[0] ^ 0 , next = 0;
		cout << 0 << " ";
		for (int i = 1; i < n; i++) {
			next = 0;
			for (int bit = 0; bit <= 30; bit++) {
				if (prev & (1 << bit)) {
					if (!(a[i] & (1 << bit))) {
						next += (1 << bit);
					}
				}
			}
			cout << next << " \n"[i == n - 1];
			prev = a[i] ^ next;
		}
	}
}