#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long mint = 0x7fffffff;
const long long linf = 1000000000000000000LL;
const long long mod = 998244353LL;
const double eps = 1e-3;
const int N = 100020;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
set<long long> s;
void f(int n) {
  for (int i = 0; i < 10; i++) {
    printf("%d", n % 4);
    n /= 4;
  }
  printf("\n");
}
int main(void) {
  vector<long long> vv, m4;
  vv.push_back(0);
  for (long long i = 1; i <= 1e16; i *= 4) {
    vv.push_back(*vv.rbegin() + i);
    m4.push_back(i);
  }
  vv.push_back(linf);
  int ttt = read();
  for (int _ = 1; _ <= ttt; _++) {
    long long n = read();
    long long g = (n - 1) / 3;
    long long nn[4];
    if (n == 1) {
      printf("1\n");
      continue;
    }
    if (n == 2) {
      printf("2\n");
      continue;
    }
    if (n == 3) {
      printf("3\n");
      continue;
    }
    nn[1] = g - 1;
    long long mt = upper_bound(vv.begin(), vv.end(), g) - vv.begin() - 1;
    long long qqq = 1;
    for (qqq = 1; qqq <= nn[1]; qqq *= 4) continue;
    nn[1] = g - vv[mt] + m4[mt];
    nn[2] = 0;
    long long tn2 = nn[1];
    for (qqq = 1; tn2 > 0; qqq *= 4) {
      if (tn2 % 4 == 1) nn[2] += qqq * 2;
      if (tn2 % 4 == 2) nn[2] += qqq * 3;
      if (tn2 % 4 == 3) nn[2] += qqq * 1;
      tn2 /= 4;
    }
    nn[0] = nn[1] ^ nn[2];
    printf("%lld\n", nn[n % 3]);
  }
  return 0;
}
