#include <bits/stdc++.h>
using namespace std;
long long a[4] = {0, 2, 3, 1};
inline long long c2(long long n, long long d) {
  if (n == 1) return 1;
  long long m = n / 4;
  for (int i = 0; i <= 3; ++i)
    if ((i + 1) * m >= d) return c2(m, d - i * m) + a[i] * m;
}
inline long long calc2(long long n) {
  long long num = 2, t = 1;
  while (n > 0) {
    if (n - t <= 0) break;
    n -= t;
    t *= 4;
    num <<= 2;
  }
  return num - 1 + c2(t, n);
}
inline long long calc1(long long n) {
  long long num = 1, t = 1;
  while (n > 0) {
    if (n - t <= 0) break;
    n -= t;
    num <<= 2;
    t *= 4;
  }
  return num - 1 + n;
}
int main() {
  int t;
  scanf("%d", &t);
  long long n;
  while (t--) {
    scanf("%lld", &n);
    long long P = (n + 2) / 3;
    if (n % 3 == 1)
      printf("%lld\n", calc1(P));
    else if (n % 3 == 2)
      printf("%lld\n", calc2(P));
    else {
      long long res1 = calc1(P);
      long long res2 = calc2(P);
      printf("%lld\n", res1 ^ res2);
    }
  }
  return 0;
}
