#include <bits/stdc++.h>
using namespace std;
int pp[3][4] = {{0, 1, 2, 3}, {0, 2, 3, 1}, {0, 3, 1, 2}};
void cl(long long target, int *pz, long long k) {
  long long temp = 1;
  while (temp < target) {
    target -= temp;
    temp <<= 2;
  }
  long long ans = temp * k;
  temp >>= 2;
  target--;
  while (temp > 0) {
    ans += pz[target / temp] * temp;
    target %= temp;
    temp >>= 2;
  }
  printf("%I64d\n", ans);
}
int main() {
  int T;
  long long n;
  scanf("%d", &T);
  while (T--) {
    scanf("%I64d", &n);
    long long bz = (n - 1) / 3 + 1, pz = (n - 1) % 3;
    cl(bz, pp[pz], pz + 1);
  }
  return 0;
}
