#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int P = 1e9 + 7;
const int INF = 0x3f3f3f3f;
int t;
long long n;
int f[3][4] = {{0, 3, 1, 2}, {}, {0, 2, 3, 1}};
long long cal(long long a, long long b) {
  long long res = 0, p = 1;
  if (b == 1) return a;
  while (a) {
    res = res + f[b][a % 4] * p;
    a >>= 2;
    p <<= 2;
  }
  return res;
}
void solve() {
  long long j = 1, a;
  while (j <= n) j <<= 2;
  j >>= 2;
  if (j + 2 >= n)
    a = j;
  else
    a = j + (n - j) / 3;
  printf("%lld\n", cal(a, n % 3));
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%lld", &n);
    solve();
  }
  return 0;
}
