#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, i, j, ii, jj, zx, xc, dp[8000009], f[1000009];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> a;
  for (i = 1; i <= a; i++) {
    cin >> f[i];
    dp[f[i]] = f[i];
  }
  for (i = 0; i < 22; i++) {
    for (j = 1; j < (1 << 22); j++) {
      if (((1 << i) & j) == 0) continue;
      if (dp[(j ^ (1 << i))] != 0) {
        dp[j] = dp[(j ^ (1 << i))];
      }
    }
  }
  for (i = 1; i <= a; i++) {
    f[i] = (1 << 22) - 1 - f[i];
    if (dp[f[i]] == 0) {
      cout << -1 << " ";
    } else {
      cout << dp[f[i]] << " ";
    }
  }
  return 0;
}
