#include <bits/stdc++.h>
using namespace std;
const int MAXN = 0x3f3f3f3f;
const int MAXL = 0x7ffff;
inline int read() {
  int x = 0, k = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') k = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * k;
}
inline void write(int re) {
  if (re > 9) write(re / 10);
  putchar(re % 10 + '0');
}
int a[1919191];
int f[1 << 22];
int n, m;
int MAX;
int main() {
  n = read();
  MAX = (1 << 22);
  MAX--;
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    f[MAX ^ a[i]] = a[i];
  }
  for (int i = MAX; i >= 0; i--) {
    if (f[i]) continue;
    for (int j = 0; j < 22; j++) {
      if (f[i | (1 << j)]) {
        f[i] = f[i | (1 << j)];
        break;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (f[a[i]])
      printf("%d ", f[a[i]]);
    else
      printf("-1 ");
  }
}
