#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const long long mod = 998244353;
const long long maxn = 1e5 + 10;
long long p[2] = {1000000007, 998244353};
long long seed[2] = {500000004, 500000004};
long long ksm(long long x, long long y) {
  long long re = 1, xx = x % mod;
  while (y > 0) {
    if (y & 1) {
      re *= xx;
      re %= mod;
    }
    xx *= xx;
    xx %= mod;
    y >>= 1;
  }
  return re;
}
long long tt, n;
long long dp[66], qzh[66];
long long c[2][4] = {{0, 2, 3, 1}, {0, 3, 1, 2}};
int main() {
  dp[1] = 1;
  for (int i = 2; i <= 30; i++) dp[i] = dp[i - 1] * 4;
  scanf("%lld", &tt);
  while (tt--) {
    scanf("%lld", &n);
    if (n == 1) {
      printf("1\n");
      continue;
    } else if (n == 2) {
      printf("2\n");
      continue;
    } else if (n == 3) {
      printf("3\n");
      continue;
    }
    long long x, y, z;
    x = n / 3;
    y = n % 3;
    if (y > 0)
      x++;
    else
      y = 3;
    long long sum = 0;
    for (int i = 1; i <= 30; i++) {
      sum += dp[i];
      if (sum >= x) {
        sum -= dp[i];
        x -= sum;
        z = dp[i];
        break;
      }
    }
    x--;
    if (y == 1) {
      printf("%lld\n", z + x);
    } else {
      z *= y;
      long long ls = 0;
      long long xx = 1;
      while (x > 0) {
        ls += c[y - 2][x % 4] * xx;
        xx *= 4;
        x /= 4;
      }
      ls += z;
      printf("%lld\n", ls);
    }
  }
  return 0;
}
