#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const int mod = 998244353;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n;
    scanf("%I64d", &n);
    long long cnt = 1;
    while (cnt <= n) cnt <<= 2;
    cnt >>= 2;
    if (n % 3 == 1) {
      printf("%I64d\n", (n - cnt) / 3 + cnt);
    } else if (n % 3 == 2) {
      long long ans = 0;
      int dig = 0;
      n -= cnt;
      n /= 3;
      while (n) {
        if (n % 4 == 1) ans += (2ll << dig);
        if (n % 4 == 2) ans += (3ll << dig);
        if (n % 4 == 3) ans += (1ll << dig);
        dig += 2;
        n /= 4;
      }
      printf("%I64d\n", ans + cnt * 2);
    } else {
      long long ans = 0;
      int dig = 0;
      n -= cnt;
      n /= 3;
      while (n) {
        if (n % 4 == 1) ans += (3ll << dig);
        if (n % 4 == 2) ans += (1ll << dig);
        if (n % 4 == 3) ans += (2ll << dig);
        dig += 2;
        n /= 4;
      }
      printf("%I64d\n", ans + 3 * cnt);
    }
  }
  return 0;
}
