#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ld = long double;
const ld EPS = 1e-8;
const ll MOD = 1e9 + 7;
const ld PI = 3.141592653589793;
const int maxn = 1001;
void fast_io() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
vector<ll> solve(vector<ll> quer) {
  vector<ll> res;
  function<ll(ll, ll, ll)> get_corr_fi = [&](ll l, ll r, ll row) {
    if (l == r - 1) {
      return l;
    }
    ll length = (r - l) / 4;
    if (row < length) {
      return get_corr_fi(l, l + length, row % length);
    }
    if (row >= 3 * length) {
      return get_corr_fi(l + length, l + 2 * length, row % length);
    }
    if (row < 2 * length) {
      return get_corr_fi(l + 2 * length, l + 3 * length, row % length);
    }
    return get_corr_fi(l + 3 * length, l + 4 * length, row % length);
  };
  for (ll n : quer) {
    ll pw_small = 1;
    for (ll i = 2;; ++i) {
      if ((1ll << i) > n) {
        break;
      }
      if ((1ll << i) % 3 == 1) {
        pw_small = 1ll << i;
      }
    }
    n -= pw_small;
    ll ans;
    if (n % 3 == 0) {
      ans = pw_small + n / 3;
    } else if (n % 3 == 1) {
      ans = get_corr_fi(2 * pw_small, 3 * pw_small, n / 3);
    } else {
      ll zer = pw_small + n / 3;
      ll fi = get_corr_fi(2 * pw_small, 3 * pw_small, n / 3);
      ans = zer ^ fi;
    }
    res.push_back(ans);
  }
  return res;
}
signed main() {
  mt19937 mt(
      std::chrono::high_resolution_clock::now().time_since_epoch().count());
  fast_io();
  cout.precision(10);
  cout << fixed;
  auto start = chrono::steady_clock::now();
  ifstream ifs("../tmp");
  vector<ll> correct;
  for (int i = 1; i <= 255; ++i) {
    int el;
    ifs >> el;
    correct.push_back(el);
  }
  int t;
  cin >> t;
  vector<ll> test;
  while (t--) {
    ll n;
    cin >> n;
    test.push_back(n);
  }
  auto res = solve(test);
  for (auto el : res) {
    cout << el << "\n";
  }
  auto end = chrono::steady_clock::now();
  42;
}
