#include <bits/stdc++.h>
using namespace std;
int nxt() {
  int ret;
  scanf("%d", &ret);
  return ret;
}
int dp[1 << 23];
const int maxn = 1e6 + 10;
int a[maxn];
signed main() {
  int n = nxt();
  for (int i = (1); i <= (n); ++i) {
    a[i] = nxt();
    dp[((1 << 23) - 1) ^ a[i]] = a[i];
  }
  for (int cur = (1 << 23) - 1; cur; cur--) {
    if (!dp[cur]) {
      for (int i = (0); i <= (22); ++i) {
        if (dp[cur | (1 << i)]) {
          dp[cur] = dp[cur | (1 << i)];
          break;
        }
      }
    }
  }
  for (int i = (1); i <= (n); ++i) {
    if (dp[a[i]])
      cout << dp[a[i]] << " ";
    else
      cout << -1 << " ";
  }
}
