#include <bits/stdc++.h>
using namespace std;
int a[1000100], dp[1 << 23], sit[23], cnt, st[1 << 23];
bool flag[1 << 23];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    dp[a[i] ^ ((1 << 23) - 1)] = a[i];
  }
  for (int st = (1 << 23) - 1; st >= 0; st--) {
    if (dp[st]) {
      for (int i = 0; i < 23; i++)
        if ((st & (1 << i)) && !dp[st ^ (1 << i)]) dp[st ^ (1 << i)] = dp[st];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dp[a[i]])
      printf("%d ", dp[a[i]]);
    else
      printf("-1 ");
  }
  return 0;
}
