#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long 
#define ull unsigned long long

/*------------------------------------------------------------------*/
 
int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

   unsigned int i, x, bs, bi;
   int n, pf[35];

   cin >> n;

   while (n--) {
      cin >> x;

      i = 0;
      bs = 49;
      bi = 0;

      if (x == 0) {
         cout << 0 << " ";
         continue;
      }

      while (x > 0)
      {
         i++;
         if (x & 1) pf[i] = 1;
         else pf[i] = 0;

         if (pf[i] == 1 && bs == 49) bs = i;
         else if(pf[i] == 0) bi = i;
         x >>= 1;
      }

      if (bs < bi)
      {
         int aux = pf[bs];
         pf[bs] = pf[bi];
         pf[bi] = aux;
      }

      int aux = pf[i];
      for (int j = i - 1; j > 0; --j) aux = (aux << 1) + pf[j];
      cout << aux <<" ";
   }
   return 0;
}