#include <bits/stdc++.h>
using namespace std;
int T;
long long n;
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%lld", &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) {
        if (p % 4 == 1)
          ans += c * 2;
        else if (p % 4 == 2)
          ans += c * 3;
        else if (p % 4 == 3)
          ans += c;
        p >>= 2, c <<= 2;
      }
      printf("%lld\n", ans);
    } else {
      long long ans = s * 3, c = 1;
      while (p) {
        if (p % 4 == 1)
          ans += c * 3;
        else if (p % 4 == 2)
          ans += c * 1;
        else if (p % 4 == 3)
          ans += c * 2;
        p >>= 2, c <<= 2;
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}
