#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
const long long A[] = {0, 2, 3, 1};
int _w;
long long bin[N], n;
void solve(void) {
  _w = scanf("%lld", &n);
  int cur;
  for (cur = 0; cur <= 30; ++cur)
    if (bin[cur + 1] > (n + 2) / 3) break;
  long long num = (1LL << cur * 2) + ((n + 2) / 3) - bin[cur];
  if (n % 3 == 1) return printf("%lld\n", num), void();
  long long a = 1LL << ((cur)*2 + 1);
  for (int i = 0; (1LL << i) < num; i += 2) a |= (A[(num >> i) & 3] << i);
  long long b = num ^ a;
  if (n % 3)
    printf("%lld\n", a);
  else
    printf("%lld\n", b);
}
int main(void) {
  int T;
  bin[0] = 1;
  for (int i = 1; i < 31; ++i) bin[i] = (bin[i - 1] + (1LL << ((i - 1) * 2)));
  _w = scanf("%d", &T);
  while (T--) solve();
  return 0;
}
