#include <bits/stdc++.h>
using namespace std;
const long long int conv[][3] = {{1, 2, 3}, {2, 3, 1}, {3, 1, 2}};
void solve(long long int n) {
  int r = n % 3;
  if (r != 0) n = (n / 3 + 1) * 3;
  if (r == 0)
    r = 2;
  else
    r = r - 1;
  int k = 0;
  long long int cnt = 3;
  while (cnt < n) {
    k++;
    cnt += 3 * pow(4, k);
  }
  cnt -= 3 * pow(4, k);
  cnt = n - cnt;
  vector<int> v(k + 1);
  v[0] = 1;
  int j;
  for (int i = 1; i < k + 1; i++) {
    for (j = 0; j < 4; j++) {
      cnt -= 3 * pow(4, k - i);
      if (cnt <= 0) {
        cnt += 3 * pow(4, k - i);
        break;
      }
    }
    v[i] = j;
  }
  long long int ans = 0;
  for (int i = 0; i < k + 1; i++) {
    if (v[i] > 0) {
      ans += conv[v[i] - 1][r] << (2 * (k - i));
    }
  }
  printf("%lld\n", ans);
}
int main() {
  int t;
  long long int n;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld", &n);
    solve(n);
  }
  return 0;
}
