#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 96;
const int MAXN = 1e6 + 5;
const int MAXK = 8e6 + 5;
const int MOD = 1e9 + 7;
const int MAX_ASCII_CODE = 26;
const int MAX_NUMBER_OF_NODES = 1e5 + 5;
int n, m;
int arr[MAXN];
int rea[MAXK];
int foo(int v) {
  if (v == 0) return -2;
  if (rea[v] != -1) return rea[v];
  if (rea[v] == -2) return -2;
  int ho = -2;
  for (int i = (int)0; i < (int)(22); i++) {
    if ((v & (1 << i)) > 0) {
      ho = max(foo((v ^ (1 << i))), ho);
    }
  }
  rea[v] = ho;
  return rea[v];
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(NULL);
  cout << fixed << setprecision(11);
  int t = 1;
  while (t--) {
    cin >> n;
    memset(rea, -1, sizeof(rea));
    for (int i = (int)0; i < (int)(n); i++) {
      cin >> arr[i];
      rea[arr[i]] = arr[i];
    }
    int t;
    int no = (1 << 22) - 1;
    for (int i = (int)0; i < (int)(n); i++) {
      t = arr[i];
      t = (no ^ arr[i]);
      cout << max(-1, foo(t)) << " ";
    }
    cout << "\n";
  }
}
