#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
const long long maxn = 1e5 + 7;
const double pi = acos(-1);
using namespace std;
long long t, n, m;
long long hang;
long long weizhi;
long long temp;
long long four = 1;
long long weishu;
long long weishu2;
long long lie;
int ans[50];
map<int, int> MP;
long long cal() {
  long long res = 0;
  long long a = 1;
  weishu2 = weishu;
  for (int i = weishu2; i >= 1; i--) {
    res += a * ans[i];
    a <<= 2;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  MP[1] = 2;
  MP[2] = 3;
  MP[3] = 1;
  cin >> t;
  while (t--) {
    memset(ans, 0, sizeof(ans));
    weishu = 1;
    four = 1;
    cin >> n;
    hang = (n - 1) / 3 + 1;
    while (hang > four) {
      hang -= four;
      four <<= 2;
      weishu++;
    }
    if (n % 3 == 0) {
      lie = 3;
    } else {
      lie = n % 3;
    }
    weishu2 = weishu;
    temp = hang - 1;
    while (temp) {
      ans[weishu2--] = temp % 4;
      temp >>= 2;
    }
    ans[1] = 1;
    if (lie == 2) {
      for (int i = 1; i <= weishu; i++) {
        ans[i] = MP[ans[i]];
      }
    } else if (lie == 3) {
      for (int i = 1; i <= weishu; i++) {
        ans[i] = MP[ans[i]];
        ans[i] = MP[ans[i]];
      }
    }
    cout << cal() << endl;
  }
  return 0;
}
