#include <bits/stdc++.h>
const int mv = (1 << 22) - 1;
int A[1000009], dp[mv + 1];
int main() {
  int n, i, j;
  scanf("%d", &n);
  memset(dp, -1, sizeof(dp));
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
    dp[A[i]] = A[i];
  }
  for (int mask = 1; mask <= mv; mask++) {
    if (dp[mask] == -1) {
      for (int j = 0; j < 22; j++) {
        if (mask & (1 << j)) {
          if (dp[mask ^ (1 << j)] != -1) {
            dp[mask] = dp[mask ^ (1 << j)];
            break;
          }
        }
      }
    }
  }
  for (i = 0; i < n; i++) printf("%d ", dp[~A[i] & mv]);
}
