#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define ls (rt<<1)
#define rs (rt<<1|1)
#define mid (l+r>>1)
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define lowbit(x) (x&(-x))
#define inc(i, l, r) for(int i=l; i<=r; i++)
#define dec(i, r, l) for(int i=r; i>=l; i--)
const int inf = 0x3f3f3f3f;
const int maxn = 1e6+10;
const double pi = acos(-1.0);
const double eps = 1e-7;
const int mod = 1e9+7;
int readint()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
ll readll(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n, m;
int num[1<<22|1];
int dp[1<<22|1];
int tt[4000000+10];
int ans[4000000+10];
int nn[4000000+10];
int main()
{
n=readint();
cls(dp, -1);
inc(i, 1, n) nn[i] = readint(), dp[nn[i]] = nn[i];
for(int mask=0; mask<(1<<22); mask++){
for(int i=0; i<=21; i++){
if(mask&(1<<i)){
if(dp[mask^(1<<i)] != -1) dp[mask] = dp[mask^(1<<i)];
}
else{
if(dp[mask] != -1) dp[mask] = dp[mask];
}
}
}
for(int i=1; i<=n; i++){
printf("%d ", dp[(1<<22)-1-nn[i]]);
}
return 0;
}