#include <bits/stdc++.h>
using namespace std;
long long p[100007] = {0, 1, 2, 3, 4, 8, 12, 5, 10, 15, 6, 11, 13, 7, 9, 14};
long long cha[17] = {0, 1, 2, 3};
long long n, L;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    cin >> n;
    --n;
    long long cha = n % 3;
    n /= 3;
    L = 0;
    long long temp = 0;
    while (n >= (1ll << L)) {
      temp = (1ll << L);
      L += 2;
      n -= temp;
    }
    for (long long i = 0; i < L; i += 2) {
      long long z = (n >> i);
      long long y = z & 3;
      if (y > 0) {
        long long zz = y << i;
        y = (cha + y) % 3;
        n ^= zz;
        if (y == 0) y = 3;
        zz = y << i;
        n ^= zz;
      }
    }
    if (cha == 1)
      n |= 1ll << (L + 1);
    else if (cha == 2 || cha == 0) {
      temp = (1ll << L);
      n |= temp;
      if (cha != 0) {
        long long tt = (1ll << (L + 1));
        n |= tt;
      }
    }
    cout << n << "\n";
  }
  return 0;
}
