#include <bits/stdc++.h>
using namespace std;
int t;
long long n;
int main() {
  cin >> t;
  while (t--) {
    scanf("%lld", &n);
    int ty = n % 3;
    n = (n - 1) / 3;
    for (int i = 0; true; ++i)
      if (n >= (1ll << (i << 1)))
        n -= 1ll << (i << 1);
      else {
        long long b = n;
        for (int j = 0; j < i; ++j)
          if ((b & (3ll << (j << 1))) == (3ll << (j << 1)))
            b ^= (2ll << (j << 1));
          else if ((b & (2ll << (j << 1))) == (2ll << (j << 1)))
            b ^= (1ll << (j << 1));
          else if (b & (1ll << (j << 1)))
            b ^= (3ll << (j << 1));
        if (ty == 1)
          printf("%lld\n", (1ll << (i << 1)) + n);
        else if (ty == 2)
          printf("%lld\n", (2ll << (i << 1)) + b);
        else
          printf("%lld\n", (3ll << (i << 1)) + (n ^ b));
        break;
      }
  }
}
