#include <bits/stdc++.h>
using namespace std;
int get_kuai(long long a) {
  int res = 0;
  a = a * 3 + 1;
  long long now = 1;
  for (int i = 1;; i++) {
    now *= 4;
    if (now >= a) {
      return i;
    }
  }
}
long long four[30];
void init() {
  four[0] = 1;
  for (int i = 1; i < 30; i++) {
    four[i] = four[i - 1] * 4;
    if (four[i] > 1e16) break;
  }
}
long long get_all(int kuai) { return (four[kuai] - 1) / 3; }
int ans[50];
int main() {
  init();
  int T;
  scanf("%d", &T);
  int g[5][4] = {0, 1, 2, 3, 0, 2, 3, 1, 0, 3, 1, 2};
  while (T--) {
    long long n;
    scanf("%lld", &n);
    long long row = (n - 1) / 3 + 1;
    long long col = (n - 1) % 3 + 1;
    long long kuai = get_kuai(row);
    row = row - get_all(kuai - 1);
    long long now = 1;
    for (int i = 0; i < kuai - 1; i++) {
      ans[i] = g[col - 1][(row - 1) / now % 4];
      now *= 4;
    }
    ans[kuai - 1] = col;
    long long res = 0;
    for (int i = 0; i < kuai; i++) {
      res = res + four[i] * ans[i];
    }
    printf("%lld\n", res);
  }
  return 0;
}
