#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
const int Z = 22;
int n, a[N], dp[1 << Z];
int main() {
  cin >> n;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < n; i++) cin >> a[i], dp[a[i]] = a[i];
  for (int i = 0; i < (1 << Z); i++) {
    for (int j = 0; j < Z; j++) dp[i] = max(dp[i], dp[i & ~(1 << j)]);
  }
  for (int i = 0; i < n; i++) cout << dp[((1 << Z) - 1) & ~a[i]] << endl;
}
