#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;
static constexpr int INF = (int)1e9 + 5;
static constexpr ll INFL = (ll)1e18 + 5;
static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(
                       chrono::high_resolution_clock::now().time_since_epoch())
                       .count());
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    if (n < 4) {
      cout << n << '\n';
      continue;
    }
    int exp = (sizeof(ll) * 8 - 1 - __builtin_clzll(n)) / 2;
    ll base = 1;
    for (int _ = 0; _ < (exp); ++_) base *= 4;
    n -= base;
    switch (n % 3) {
      case 0:
        cout << (base + n / 3) << '\n';
        break;
      case 1: {
        ll r = base * 2;
        ll e = 1;
        array<ll, 4> a = {0, 2, 3, 1};
        for (int _ = 0; _ < (exp); ++_) r += a[(n / 3) / e % 4] * e, e *= 4;
        cout << r << '\n';
        break;
      }
      case 2: {
        ll r = base * 3;
        ll e = 1;
        array<ll, 4> a = {0, 3, 1, 2};
        for (int _ = 0; _ < (exp); ++_) r += a[(n / 3) / e % 4] * e, e *= 4;
        cout << r << '\n';
        break;
      }
    }
  }
  return 0;
}
