#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int cases;
  cin >> cases;
  while (cases--) {
    long long n;
    cin >> n;
    long long m = n / 3;
    if (n == m * 3) m--;
    long long mm = m + 1;
    long long x = 0;
    while (mm - pow(4, x) > 0) {
      mm -= pow(4, x);
      x++;
    }
    long long num = pow(4, x) - 1 + mm;
    n %= 3;
    if (n == 1) {
      cout << num << "\n";
      continue;
    }
    long long ans = 0;
    for (int i = 0; i < x + 1; i++) {
      long long liek = num % 4;
      if (liek == 1) {
        if (n == 2)
          ans += 2 * (1ll << (2 * i));
        else
          ans += 3 * (1ll << (2 * i));
      } else if (liek == 2) {
        if (n == 2)
          ans += 3 * (1ll << (2 * i));
        else
          ans += 1 * (1ll << (2 * i));
      } else if (liek == 3) {
        if (n == 2)
          ans += 1 * (1ll << (2 * i));
        else
          ans += 2 * (1ll << (2 * i));
      }
      num /= 4;
    }
    cout << ans << "\n";
  }
  return 0;
}
