#include <bits/stdc++.h>
using namespace std;
int t;
long long n;
long long d0[4] = {0, 3, 1, 2};
long long d2[4] = {0, 2, 3, 1};
void work() {
  scanf("%lld", &n);
  if (n <= 3) {
    printf("%lld\n", n);
    return;
  }
  if (n % 3 == 1) {
    long long now = n / 3;
    long long nowd = 4;
    while (now > nowd) {
      now -= nowd;
      nowd *= 4;
    }
    printf("%lld\n", nowd + now - 1);
    return;
  } else if (n % 3 == 0) {
    long long now = n / 3;
    now--;
    long long nowd = 4;
    while (now > nowd) {
      now -= nowd;
      nowd *= 4;
    }
    long long ans = nowd * 3;
    while (nowd >= 4) {
      nowd /= 4;
      ans += d0[(now - 1) / nowd] * nowd;
      now = now % nowd;
      if (now == 0) now = nowd;
    }
    printf("%lld\n", ans);
    return;
  } else if (n % 3 == 2) {
    long long now = n / 3;
    long long nowd = 4;
    while (now > nowd) {
      now -= nowd;
      nowd *= 4;
    }
    long long ans = nowd * 2;
    while (nowd >= 4) {
      nowd /= 4;
      ans += d2[(now - 1) / nowd] * nowd;
      now = now % nowd;
      if (now == 0) now = nowd;
    }
    printf("%lld\n", ans);
    return;
  }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    work();
  }
}
