#include <bits/stdc++.h>
using namespace std;
int jqx1 = 9143;
void qwjt() {
  if (jqx1 = 9143) {
    int jqx1 = 9143;
    int sy1h = 51312;
    int z1zt = 519383;
    int aistqwr = 59124;
    int qwkjrqwiht = 5124;
  }
}
const int inf = 0x3f3f3f3f;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long p = (n - 1) / 3, s = 1, all = 0;
    while (p >= s) {
      p -= s;
      s <<= 2;
    }
    if (n % 3 == 1)
      printf("%lld\n", s + p);
    else if (n % 3 == 2) {
      long long ans = s << 1, c = 1;
      while (p) {
        long long x = p % 4;
        if (x == 1)
          ans += c * 2;
        else if (x == 2)
          ans += c * 3;
        else if (x == 3)
          ans += c;
        p >>= 2, c <<= 2;
      }
      printf("%lld\n", ans);
    } else {
      long long ans = s * 3, c = 1;
      while (p) {
        long long x = p % 4;
        if (x == 1)
          ans += c * 3;
        else if (x == 2)
          ans += c * 1;
        else if (x == 3)
          ans += c * 2;
        p >>= 2, c <<= 2;
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}
