#include <bits/stdc++.h>

using namespace std;

#define int long long

int solve(int x) {
	vector<int> bits;
	while(x) bits.push_back(x % 2), x /= 2;
	sort(bits.rbegin(), bits.rend());
	int ret = 0;
	for(auto x : bits) ret = ret * 2 + x;
	return ret;
}

int32_t main() {
	int n;
	cin >> n;

	for(int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		cout << solve(x) << " ";
	}
	return 0;
}