#include <bits/stdc++.h>
using namespace std;
int64_t ar[64];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ar[0] = 3;
  for (int64_t i = 1; i < 30; i++) {
    ar[i] = ar[i - 1] + 3 * pow(2, 2 * i);
  }
  int64_t t;
  cin >> t;
  while (t--) {
    int64_t n;
    cin >> n;
    int64_t pos = 0;
    while (ar[pos] < n) {
      pos++;
    }
    int64_t base = pow(2, 2 * pos);
    int64_t top = n - base;
    top /= 3;
    base += top;
    int64_t scnd = 0;
    int64_t temp = base;
    int64_t p4 = 1;
    while (temp > 0) {
      if (temp % 4 == 1) {
        scnd += 2 * p4;
      } else if (temp % 4 == 2) {
        scnd += 3 * p4;
      } else if (temp % 4 == 3) {
        scnd += p4;
      }
      temp /= 4;
      p4 *= 4;
    }
    if (n % 3 == 1) {
      cout << base << "\n";
    } else if (n % 3 == 2) {
      cout << scnd << "\n";
    } else {
      cout << (scnd ^ base) << "\n";
    }
  }
  return 0;
}
