#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int T;
  cin >> T;
  for (int t = 0; t < T; t++) {
    long long n;
    cin >> n;
    long long currentK = 0;
    long long seen = 0;
    n--;
    long long transformations[3][4] = {
        {0, 1, 2, 3}, {0, 2, 3, 1}, {0, 3, 1, 2}};
    while (true) {
      if (3 * (1ll << currentK) > n) {
        long long solution = 0;
        long long rem = n % 3;
        n /= 3;
        solution += ((rem + 1) << currentK);
        for (int i = 0; i <= currentK + 2; i += 2) {
          solution |= ((transformations[rem % 3][(n >> (i)) & 3]) << i);
        }
        cout << solution << "\n";
        break;
      } else {
        n -= 3 * (1ll << currentK);
        currentK += 2;
      }
    }
  }
  return 0;
}
