#include <bits/stdc++.h>

using namespace std;

inline void debugMode() {
    #ifndef ONLINE_JUDGE
    freopen("debug.in", "r", stdin);
    #endif // ONLINE_JUDGE
}



int main()
{
    ios :: sync_with_stdio(false);
    debugMode();

    unsigned long long n,x,k,kk;

    cin >> n;

    for(int i = 1; i <= n; i++){

        k = 0;
        kk = 0;

        cin >> x;

        while(x != 0){
            k++;
            if(x % 2 == 1)
                kk++;
            x /=2;
        }

        for(;kk > 0 && k - 1 > 0;kk--,k--)
            x = x + 1LL * (1 << (k - 1));

        cout << x << " ";

    }

    return 0;
}