#include <bits/stdc++.h>

using namespace std;

int solve(int x) {
  if (x == 0) {
    return 0;
  }

  int firstOne = -1;
  int firstZero = -1;
  int lastOne = -1;
  for (int i = 31; i >= 0; i--) {
    if (x & (1 << i)) {
      lastOne = i;
      if (firstOne == -1) {
        firstOne = i;
      }
    } else {
      if (firstOne != -1) {
        if (firstZero == -1) {
          firstZero = i;
        }
      }
    }
  }

  // cerr << x << ' ' << firstZero << ' ' << lastOne << ' ' << firstOne << endl;
  if (firstZero != -1 && lastOne != -1 && lastOne != firstOne && lastOne < firstZero) {
    x = x - (1 << lastOne) + (1 << firstZero);
  }

  return x;
}

int main() {
	// assert(freopen("bits.in", "r", stdin));
	// assert(freopen("bits.out", "w", stdout));
	cin.sync_with_stdio(false);

  int N;
	cin >> N;

  while (N--) {
    int x;
    cin >> x;

    int ans = solve(x);
    cout << ans << ' ';
  }
  cout << endl;

	return 0;
}