#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ll long long
#define pii pair<int,int>
#define tii tuple <int,int,int>
#define N 100005
#define mod 2000003
#define X first
#define Y second
#define eps 0.0000000001
#define all(x) x.begin(),x.end()
#define tot(x) x+1,x+n+1
using namespace std;
ll a, b, x, y, n, i, sol,   j;
int main() {
    cin.sync_with_stdio(0);
    cout.sync_with_stdio(0);
    cin >> n;

    for(i = 1; i <= n; i++) {
        cin >> a;
        y = -1;
        j = -1;
        x = log2(a) ;

        for(j = x; j >= 0; j--)
            if((a & (1 << j)) == 0)
                break;

        y = j;

        for(j--; j >= 0; j--)
            if((a & (1 << j)) == 1)
                break;

        sol = a;

        if(y >= 0&& j >= 0)
            sol = a - (1 << j) + (1 << y);

        cout << sol << ' ';
    }

    return 0;
}