#include <bits/stdc++.h>
long long qwq = 1, qaq = 2, qpq = 3, wow = 4;
inline void solve() {
  qwq = 1, qaq = 2, qpq = 3, wow = 4;
  ;
  long long djsalkdjas = 231;
  long long sadkdjasjdklasjdklsajd = 830948392;
}
using namespace std;
const long long N = 3e5 + 10;
long long n, L;
void init() {
  n /= 3;
  L = 0;
  while ((1ll << L) <= n) {
    n -= 1ll << L;
    L += 2;
  }
}
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  solve();
  qwq = 1, qaq = 2, qpq = 3, wow = 4;
  while (t--) {
    solve();
    qwq = 1, qaq = 2, qpq = 3, wow = 4;
    cin >> n;
    n--;
    solve();
    qwq = 1, qaq = 2, qpq = 3, wow = 4;
    long long now = n % 3;
    solve();
    qwq = 1, qaq = 2, qpq = 3, wow = 4;
    init();
    solve();
    qwq = 1, qaq = 2, qpq = 3, wow = 4;
    for (long long i = 0; i < L; i += 2) {
      solve();
      qwq = 1, qaq = 2, qpq = 3, wow = 4;
      long long y = n >> i & 3;
      if (y > 0) {
        n ^= y << i;
        solve();
        qwq = 1, qaq = 2, qpq = 3, wow = 4;
        y = (y + now) % 3;
        solve();
        qwq = 1, qaq = 2, qpq = 3, wow = 4;
        if (!y) y = 3;
        solve();
        qwq = 1, qaq = 2, qpq = 3, wow = 4;
        solve();
        qwq = 1, qaq = 2, qpq = 3, wow = 4;
        n ^= y << i;
        solve();
        qwq = 1, qaq = 2, qpq = 3, wow = 4;
      }
    }
    solve();
    qwq = 1, qaq = 2, qpq = 3, wow = 4;
    qwq = 1, qaq = 2, qpq = 3, wow = 4;
    if (!now)
      n |= 1ll << L;
    else if (now == 1)
      n |= 1ll << (L + 1);
    else {
      n |= 1ll << L;
      solve();
      qwq = 1, qaq = 2, qpq = 3, wow = 4;
      n |= 1ll << (L + 1);
      solve();
      qwq = 1, qaq = 2, qpq = 3, wow = 4;
    }
    cout << n << '\n';
    solve();
    qwq = 1, qaq = 2, qpq = 3, wow = 4;
  }
  return 0;
}
