#include <bits/stdc++.h>
using namespace std;
long long T, n;
long long getFirst(long long n) {
  long long cur = 4;
  while (n > cur) {
    n -= cur;
    cur *= 4;
  }
  return cur + n - 1;
}
long long getSecond(long long n) {
  long long cur = 4;
  while (n > cur) {
    n -= cur;
    cur *= 4;
  }
  n--;
  vector<long long> d;
  while (n) {
    d.push_back(n % 4);
    n /= 4;
  }
  long long f[4] = {0, 2, 3, 1};
  reverse(d.begin(), d.end());
  for (auto i : d) n = n * 4ll + f[i];
  return 2ll * cur + n;
}
long long getThird(long long n) { return getFirst(n) ^ getSecond(n); }
int init() {
  scanf("%lld", &n);
  if (n <= 3) return printf("%lld\n", n), 0;
  if (n % 3 == 1) return printf("%lld\n", getFirst(n / 3));
  if (n % 3 == 2) return printf("%lld\n", getSecond(n / 3));
  return printf("%lld\n", getThird(n / 3 - 1));
}
int main() {
  scanf("%lld", &T);
  while (T--) init();
  return 0;
}
