#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:25600000")
using namespace std;
const double pi = acos(-1.0);
const int MAXN = 9 * 1024000;
bool pres[MAXN];
int a[MAXN];
int ans[MAXN];
int n;
int main() {
  for (long long i = 0; i < MAXN; i++) ans[i] = -1;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    pres[a[i]] = true;
  }
  for (long long i = 0; i < MAXN; i++) {
    if (pres[i]) {
      ans[i] = i;
      continue;
    }
    for (long long pw = 0; pw < 23; pw++)
      if (i & (1 << pw)) {
        int t = i - (1 << pw);
        if (ans[t] != -1) {
          ans[i] = ans[t];
          break;
        }
      }
  }
  for (long long i = 0; i < n; i++) {
    int t = (1 << 23) - 1;
    t ^= a[i];
    if (i) cout << " ";
    printf("%d", ans[t]);
  }
  cout << endl;
}
