#include <bits/stdc++.h>
const int inf = (int)1e9;
const int mod = 1e9 + 7;
using namespace std;
int n;
int a[1 << 23], z[1 << 23];
int inv(int x) {
  int lg = log2(x);
  int ans;
  for (int i = 22; i >= 0; i--) {
    if ((x & (1 << i)) > 0) {
      x -= (1 << i);
    } else {
      x += (1 << i);
    }
  }
  return x;
}
string per(int x) {
  string s = "";
  for (int i = log2(x); i >= 0; i--) {
    if (x >= (1 << i)) {
      x -= (1 << i);
      s += '1';
    } else {
      s += '0';
    }
  }
  return s;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  memset(z, -1, sizeof(z));
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    z[a[i]] = a[i];
  }
  for (int i = 1; i <= (1 << 22); i++) {
    if (z[i] == -1) {
      continue;
    }
    for (int j = 0; j <= 22; j++) {
      if ((i & (1 << j)) == 0) {
        z[i | (1 << j)] = z[i];
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    int y = inv(a[i]);
    cout << z[y] << " ";
  }
  return 0;
}
