#include <bits/stdc++.h>
using namespace std;
long long f(long long n) {
  --n;
  long long r = n % 3, r1 = 0;
  n /= 3;
  long long res = 0;
  vector<long long> c(60), s(62);
  for (int b = 0; b < c.size(); b += 2) {
    c[b] = 1LL << b;
    s[b + 2] = s[b] + c[b];
  }
  for (int b = 60; b >= 0; b -= 2) {
    if (n >= s[b]) {
      n -= s[b] + 1;
      if (r == 0) res += 1LL << b;
      if (r == 1) res += 1LL << (b + 1);
      if (r == 2) res += (1LL << b) * 3;
      if (n == -1) break;
      for (int b1 = 0; b1 < b; b1 += 2)
        if (n < 3 * s[b1 + 2]) {
          int t = (n - 3 * s[b1]) / c[b1];
          r = (r + t - r1 + 3) % 3;
          n = (n - 3 * s[b1]) % c[b1] + s[b1];
          r1 = t;
          break;
        }
    }
  }
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int N = 10000;
  vector<int> was(N);
  vector<long long> q;
  for (int i = 1; i < N / 4; ++i)
    if (!was[i]) {
      was[i] = 1;
      for (int j = i + 1; j < N; ++j)
        if (!was[j] && !was[i ^ j]) {
          was[j] = 1;
          was[i ^ j] = 1;
          q.push_back(i);
          q.push_back(j);
          q.push_back(i ^ j);
          break;
        }
    }
  for (int i = 0; i < q.size(); ++i) {
    long long q1 = f(i + 1);
    assert(q[i] == q1);
  }
  int T;
  cin >> T;
  for (int t = 0; t < T; ++t) {
    long long n;
    cin >> n;
    cout << f(n) << '\n';
  }
  return 0;
}
