#include <bits/stdc++.h>
using i64 = long long;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    i64 n;
    scanf("%lld", &n);
    i64 q = (n + 2) / 3, r = (n + 2) % 3;
    i64 s = 0, j = 0;
    while (s + (1ll << (2 * j)) < q) {
      s += 1ll << (2 * j);
      j++;
    }
    i64 a = q - s + (1ll << (2 * j)) - 1;
    std::vector<i64> ds;
    while (a) {
      ds.push_back(a % 4);
      a /= 4;
    }
    for (auto &e : ds) {
      if (e) e = (e - 1 + r) % 3 + 1;
    }
    i64 ret = 0;
    for (i64 i = 0; i < ds.size(); i++) ret += ds[i] * (1ll << (2 * i));
    printf("%lld\n", ret);
  }
  return 0;
}
