#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int MAX = (1LL << 23) - 1;
const long long INF = 1e18;
const int MOD = 1e9 + 7;
int ar[MAX], dp[MAX], n;
void sol() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    dp[ar[i]] = ar[i];
  }
  for (int i = 1; i < MAX; i++) {
    if (dp[i]) continue;
    for (int j = 0; j < 23; j++) {
      if (i & (1 << j)) {
        if (dp[i ^ (1 << j)]) {
          dp[i] = dp[i ^ (1 << j)];
          break;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (dp[MAX ^ ar[i]])
      cout << dp[MAX ^ ar[i]] << " ";
    else
      cout << -1 << " ";
  }
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  { sol(); }
}
