#include <bits/stdc++.h>
using namespace std;
int T;
long long n;
long long solve2(long long st, long long len, long long ar) {
  if (len == 1) return st;
  long long d = len >> 2;
  if (ar <= d) return solve2(st, d, ar);
  ar -= d;
  if (ar <= d) return solve2(st + 2 * d, d, ar);
  ar -= d;
  if (ar <= d) return solve2(st + 3 * d, d, ar);
  ar -= d;
  if (ar <= d) return solve2(st + d, d, ar);
}
long long solve3(long long st, long long len, long long ar) {
  if (len == 1) return st;
  long long d = len >> 2;
  if (ar <= d) return solve3(st, d, ar);
  ar -= d;
  if (ar <= d) return solve3(st + 3 * d, d, ar);
  ar -= d;
  if (ar <= d) return solve3(st + d, d, ar);
  ar -= d;
  if (ar <= d) return solve3(st + 2 * d, d, ar);
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%lld", &n);
    long long ar = (n - 1) / 3 + 1, po = n % 3, st = 0;
    for (long long i = 1;; i <<= 2) {
      if (ar <= i) {
        st = i;
        break;
      }
      ar -= i;
    }
    if (po == 1) printf("%lld\n", st + ar - 1);
    if (po == 2) printf("%lld\n", solve2(st * 2, st, ar));
    if (po == 0) printf("%lld\n", solve3(st * 3, st, ar));
  }
  return 0;
}
