#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  bool f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = 0;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  if (f) return x;
  return 0 - x;
}
const int maxn = 100000 + 10;
const long long mod = 998244353;
long long n, sum[110], val[110], a[4] = {0, 2, 3, 1};
long long solve(long long x) {
  if (x == 1) return 1;
  if (x == 2) return 2;
  if (x == 3) return 3;
  long long t = (x + 2) / 3;
  int pos;
  for (int i = 2; i <= 60; i++) {
    if (sum[i] >= t) {
      pos = i - 1;
      break;
    }
  }
  long long cz = t - sum[pos] - 1;
  long long p1 = val[pos + 1] + cz;
  long long p2 = 0, now = 1, tx = p1;
  while (tx) {
    p2 += a[tx % 4] * now;
    now *= 4;
    tx /= 4;
  }
  long long p3 = p1 ^ p2;
  int f = x % 3;
  if (f == 0) return p3;
  if (f == 1) return p1;
  if (f == 2) return p2;
}
int main() {
  long long ps = 1;
  sum[1] = val[1] = 1;
  for (int i = 2; i < 60; i++) {
    ps *= 4;
    val[i] = ps;
    sum[i] = sum[i - 1] + ps;
  }
  int _;
  for (scanf("%d", &_); _; _--) {
    cin >> n;
    cout << solve(n) << endl;
  }
  return 0;
}
