#include <bits/stdc++.h>
std::string base4enc(long long n) {
  std::string s = "";
  while (n) {
    s += '0' + n % 4;
    n >>= 2;
  }
  std::reverse(s.begin(), s.end());
  return s;
}
long long base4dec(std::string s) {
  long long n = 0;
  long long mul = 1;
  for (int i = s.length() - 1; i >= 0; i--) {
    n += (long long)(s[i] - '0') * mul;
    mul *= 4LL;
  }
  return n;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::vector<long long> beg(32);
  beg[0] = 1;
  for (int i = 1; i < 32; i++) beg[i] = beg[i - 1] + 3 * (1LL << (2 * i - 2));
  int seq[3][4] = {{0, 1, 2, 3}, {0, 2, 3, 1}, {0, 3, 1, 2}};
  int T;
  std::cin >> T;
  while (T--) {
    long long N;
    std::cin >> N;
    long long dig = 0;
    while (beg[dig] <= N) dig++;
    dig--;
    long long delta = N - beg[dig];
    delta /= 3;
    std::string s = base4enc(delta);
    while (s.length() < dig) s = '0' + s;
    for (int i = 0; i < dig; i++) s[i] = seq[(N - 1) % 3][s[i] - '0'] + '0';
    s = (char)(((N - 1) % 3) + '1') + s;
    std::cout << base4dec(s) << "\n";
  }
}
