#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long i, j, k;
  long long t;
  t = 1;
  while (t--) {
    long long n;
    cin >> n;
    long long nb = 22;
    vector<long long> dp((1LL << nb), -1);
    vector<long long> v;
    for (i = (0); i < (n); i++) {
      long long x;
      cin >> x;
      dp[x] = x;
      v.push_back(x);
    }
    for (i = 0; i < nb; i++) {
      for (j = 0; j < (1ll << nb); j++) {
        if (j & (1ll << i)) {
          if (dp[j] != -1)
            dp[j] = dp[j];
          else if (dp[j ^ (1ll << i)] != -1)
            dp[j] = dp[j ^ (1ll << i)];
          else
            dp[j] = -1;
        }
      }
    }
    for (i = (0); i < (n); i++) {
      long long rem = ((1ll << nb) - 1 - v[i]);
      cout << dp[rem] << " ";
    }
    cout << '\n';
  }
  return 0;
}
