#include <bits/stdc++.h>
using namespace std;
const int init[3] = {1, 2, 3};
const vector<int> bits[4] = {{0, 0, 0}, {1, 2, 3}, {2, 3, 1}, {3, 1, 2}};
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long n;
    cin >> n;
    int numbits = 2;
    long long p = n;
    while (3 * (1LL << (numbits - 2)) < p) {
      p -= 3 * (1LL << (numbits - 2));
      numbits += 2;
    }
    long long m = (p - 1) / 3;
    long long k = (p - 1) % 3;
    long long res = 0;
    long long pw = 1;
    for (int i = 0; i < numbits / 2 - 1; ++i) {
      res = bits[m % 4][k] * pw + res;
      m /= 4;
      pw *= 4;
    }
    res = init[k] * pw + res;
    cout << res << endl;
  }
}
