#include <iostream>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <iomanip>
#include <utility>

using namespace std;

int main() {
	int testcases;
	cin >> testcases;
	for (int casenum = 0; casenum < testcases; casenum++) {
		vector<int> x;
		int n;
		cin >> n;
		for (int i = 0; i < n; i++) {
			int xi;
			cin >> xi;
			x.push_back(xi);
		}
		//y0=0
		//yn=x[n-1]and(not(x[n]))
		int y_old = 0;
		cout << 0;
		for (int i = 1; i < n; i++) {
			int y = (y_old ^ x[i-1]) & (~x[i]);
			cout << ' ' << y;
			y_old = y;
		}
		cout << endl;
	}
}
