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

int update(int x,int y,int z)
{
  for(int i=0;i<=30;i++)
  {
    int bx = x & (1 << i);
    int by = y & (1 << i);
    int bz = z & (1 << i);
    if(bx == 0 && bz > 0) z ^= (1 << i);
  }
  return z;
}
void solve()
{
  int n;
  cin >> n;
  vector<int> a(n,0);
  for(int i=0;i<n;i++) cin >> a[i];
  vector<int> ans(n,0);
  for(int i=1;i<n;i++)
  {
    int c = (a[i] ^ a[i - 1]);
    c = update(a[i - 1],a[i],c);
    ans[i] = c;
    a[i] ^= c;
  }
  for(int i=0;i<ans.size();i++) cout << ans[i] << ' ';
  cout << endl;
}
int main()
{
  int t;
  cin >> t;
  while(t--) solve();
}

