#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int vis[N];
long long dfs(long long l, long long r, long long x) {
  long long kuai = (r - l + 1) / 4;
  if (l == r) return l;
  if (x <= kuai)
    return dfs(l, l + kuai - 1, x);
  else if (x <= 2 * kuai)
    return dfs(l + 2 * kuai, l + 3 * kuai - 1, x - kuai);
  else if (x <= 3 * kuai)
    return dfs(l + 3 * kuai, r, x - 2 * kuai);
  else
    return dfs(l + kuai, l + 2 * kuai - 1, x - 3 * kuai);
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long n;
    cin >> n;
    long long a = (n + 2) / 3;
    long long b = n - (a - 1LL) * 3LL;
    long long tmp = a;
    long long pp = 1;
    while (tmp) {
      if (tmp <= pp) break;
      tmp -= pp;
      pp *= 4;
    }
    long long p1 = pp + tmp - 1;
    long long p2 = dfs(pp * 2, pp * 3 - 1, tmp);
    if (b == 1)
      cout << p1 << endl;
    else if (b == 2)
      cout << p2 << endl;
    else
      cout << (p1 ^ p2) << endl;
  }
  return 0;
}
