#include <iostream>

using namespace std;

int n, i, a, j, nrzeroi, nrunui, reprez[40], cnt, ans;

int main()
{
    cin >> n;

    for(i = 1; i <= n; i++)
    {
        cin >> a;

        cnt = nrzeroi = ans = 0;

        while(a)
        {
            reprez[++cnt] = a % 2;
            a = a / 2;
        }

        for(j = 1; j <= cnt && nrzeroi < 2; j++)
        {
            if(reprez[j])
            {
                reprez[j] = 0;
                nrzeroi++;
            }
        }

        for(j = cnt; j >= 1 && nrzeroi > 0; j--)
        {
            if(!reprez[j])
            {
                reprez[j] = 1;
                nrzeroi--;
            }
        }

        for(j = 1; j <= cnt; j++)
            ans += (reprez[j] * (1 << (j - 1)));

        cout << ans << " ";

    }
}