#include <bits/stdc++.h>
using namespace std;
const int A[4] = {0, 1, 2, 3};
const int B[4] = {0, 2, 3, 1};
const int C[4] = {0, 3, 1, 2};
int main() {
  int cases;
  scanf("%d", &cases);
  for (; cases; cases--) {
    long long n;
    scanf("%lld", &n);
    if (n <= 3) {
      printf("%lld\n", n);
      continue;
    }
    n -= 4;
    int v = n % 3;
    n /= 3;
    long long d = 1;
    int cnt = 0;
    for (;;) {
      d *= 4;
      cnt++;
      if (d > n) break;
      n -= d;
    }
    int val[60], sz = 0;
    memset(val, 0, sizeof(val));
    while (n) {
      val[++sz] = n % 4;
      n /= 4;
    }
    long long s = 0;
    if (!v) {
      s += 1;
      for (int i = cnt; i > 0; i--) s = s * 4LL + A[val[i]];
    }
    if (v == 1) {
      s += 2;
      for (int i = cnt; i > 0; i--) s = s * 4LL + B[val[i]];
    }
    if (v == 2) {
      s += 3;
      for (int i = cnt; i > 0; i--) s = s * 4LL + C[val[i]];
    }
    printf("%lld\n", s);
  }
  return 0;
}
