#include <bits/stdc++.h>
using namespace std;
long long val[(1 << 23)];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long n, q;
  cin >> n;
  long long a[n];
  memset(val, -1, sizeof(val));
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    val[a[i]] = a[i];
  }
  for (long long i = 0; i < 23; i++) {
    for (long long j = 0; j < (1 << 23); j++) {
      if (j & (1 << i)) {
        if ((val[j] == -1) && (val[j ^ (1 << i)] != -1)) {
          val[j] = val[j ^ (1 << i)];
        }
      }
    }
  }
  long long x = (1 << 23) - 1;
  for (long long i = 0; i < n; i++) {
    cout << val[x ^ a[i]] << " ";
  }
  cout << "\n";
}
