5

3 2 2
2 0
0 5

4 3 2
2 0 5
0 6

0 2 2
1 0
2 3

5 4 4
6 0 8 0
0 7 0 9

5 4 1
8 7 8 0
0

0 2 0 5
0 2 0 5 6
-1
0 6 0 7 0 8 0 9
-1

#include <bits/stdc++.h>
using namespace std;
string toBinary(int n) {
  std::string r;
  while (n != 0) {
    r = (n % 2 == 0 ? "0" : "1") + r;
    n /= 2;
  }
  return r;
}
int binaryToDecimal(string n) {
  string num = n;
  int dec_value = 0;
  int base = 1;
  int len = num.length();
  for (int i = len - 1; i >= 0; i--) {
    if (num[i] == '1') dec_value += base;
    base = base * 2;
  }
  return dec_value;
}
int check(long long a[], long long b[], int l1) {
  for (int i = 0; i < l1; i += 1) {
    if (a[i] != b[i]) {
      return false;
    }
  }
  return true;
}
void solve() {
  int n;
  cin >> n;
  long long a[n], b[n];
  for (int i = 0; i < n; i += 1) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  string s1 = "1111111111111111111";
  vector<long long> v;
  bool flag = check(a, b, n);
  if (flag == true) {
    for (int i = 0; i < n; i += 1) {
      string second = toBinary(a[i]);
      int l = second.length();
      string sub = s1.substr(0, l);
      v.push_back(abs(binaryToDecimal(sub) - a[i]));
    }
  } else {
    v.push_back(0);
    string second = toBinary(a[0]);
    int l = second.length();
    string sub = s1.substr(0, l);
    int value = binaryToDecimal(sub);
    for (int i = 1; i < n; i += 1) {
      v.push_back(abs(value - a[i]));
    }
  }
  for (int i = 0; i < v.size(); i += 1) {
    cout << v[i] << " ";
  }
  cout << endl;
}
int main() {
  int t;
  cin >> t;
  for (int m = 0; m < t; m += 1) {
    solve();
  }
  return 0;
}
