#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[N], f[N << 3];
int n, st;
int main() {
  scanf("%d", &n);
  for (int i(1); i <= (n); ++i) scanf("%d", a + i);
  memset(f, -1, sizeof f);
  st = (1 << 22) - 1;
  for (int i(1); i <= (n); ++i) f[st ^ a[i]] = a[i];
  for (int i(st); i >= (1); --i)
    if (f[i] == -1) {
      for (int j(0); j <= (21); ++j)
        if (!(i & (1 << j)) && ~f[i ^ (1 << j)]) {
          f[i] = f[i ^ (1 << j)];
          break;
        }
    }
  for (int i(1); i <= (n); ++i) printf("%d\n", f[a[i]]);
  return 0;
}
