#include <bits/stdc++.h>
using namespace std;
long long modPow(long long a, long long b) {
  long long res = 1;
  a %= 998244353;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 998244353;
    a = a * a % 998244353;
  }
  return res;
}
long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int a[3][4] = {{0, 1, 2, 3}, {0, 2, 3, 1}, {0, 3, 1, 2}};
int b[] = {1, 2, 3};
void solve() {
  long long n;
  cin >> n;
  long long k = 1 + (n - 1) / 3;
  int t = (n - 1) % 3;
  int sz = 0;
  long long d = 1;
  while (d < k) {
    k -= d;
    d *= 4;
    sz++;
  }
  long long ans = b[t];
  for (int i = 1; i <= sz; i++) {
    int t2 = 0;
    d /= 4;
    while (d < k) {
      k -= d;
      t2++;
    }
    ans = (ans * 4) + a[t][t2];
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int testCases = 1;
  cin >> testCases;
  while (testCases--) {
    solve();
  }
  return 0;
}
