#include <bits/stdc++.h>
using namespace std;
int f[3][4] = {{0, 3, 1, 2}, {}, {0, 2, 3, 1}};
void solve(long long x, int y) {
  if (y == 1) {
    printf("%lld\n", x);
    return;
  }
  long long ans = 0, p = 1;
  while (x) {
    ans += f[y][x % 4] * p;
    x >>= 2, p <<= 2;
  }
  printf("%lld\n", ans);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n;
    scanf("%lld", &n);
    long long j = 1, a;
    while (j <= n) j <<= 2;
    j >>= 2;
    if (j + 2 >= n)
      a = j;
    else
      a = j + (n - j) / 3;
    solve(a, n % 3);
  }
}
