#include <bits/stdc++.h>
using namespace std;
long long arr1[3] = {1, 2, 3};
long long arr2[12] = {0, 0, 0, 1, 2, 3, 2, 3, 1, 3, 1, 2};
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, x = 1;
    cin >> n;
    long long ost = (n - 1) % 3;
    n = (n - 1) / 3;
    while (n >= x) {
      n -= x;
      x *= 4;
    }
    long long sol = (ost + 1) * x;
    x /= 4;
    while (x >= 1) {
      long long z = (n / x) * 3 + ost;
      sol += arr2[z] * x;
      n %= x;
      x /= 4;
    }
    cout << sol << endl;
  }
}
