#include <bits/stdc++.h>
using namespace std;
const int order[3][4] = {{0, 1, 2, 3}, {0, 2, 3, 1}, {0, 3, 1, 2}};
long long solve(long long n) {
  long long four = 1;
  while (four * 4 <= n) {
    four *= 4;
  }
  int part = (n - 1) % 3;
  n -= four;
  n /= 3;
  long long res = four * (part + 1);
  while (n > 0) {
    res += order[part][n / four] * four;
    n %= four;
    four /= 4;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tc;
  long long n;
  cin >> tc;
  while (tc--) {
    cin >> n;
    long long ans = solve(n);
    cout << ans << '\n';
  }
  return 0;
}
