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