#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long d4 = 1, d, N, n;
  cin >> N;
  n = N;
  while (n) {
    n /= 4;
    d4 *= 4;
  }
  d = d4 / 4;
  long long ans = 0, g4 = 1, a;
  n = N;
  a = (N - d) / 3;
  if ((N - d) % 3 == 0) {
    while (a) {
      ans += g4 * (a % 4);
      a /= 4;
      g4 *= 4;
    }
    cout << ans + d << endl;
  } else if ((N - d) % 3 == 1) {
    while (a) {
      if (a % 4 == 1) ans += g4 * 2;
      if (a % 4 == 2) ans += g4 * 3;
      if (a % 4 == 3) ans += g4 * 1;
      a /= 4;
      g4 *= 4;
    }
    cout << ans + d * 2 << endl;
  } else {
    while (a) {
      if (a % 4 == 1) ans += g4 * 3;
      if (a % 4 == 2) ans += g4 * 1;
      if (a % 4 == 3) ans += g4 * 2;
      a /= 4;
      g4 *= 4;
    }
    cout << ans + d * 3 << endl;
  }
}
int main() {
  long long T;
  cin >> T;
  while (T--) {
    solve();
  }
}
