#include <bits/stdc++.h>
using namespace std;
long long arr[4] = {1, 2, 3};
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long nn = (n + 2) / 3;
    long long xx = 1, c = 0;
    while (nn > xx) nn -= xx, xx *= 4, c++;
    long long ad = ((n + 2) % 3 + 1) * xx;
    long long z = nn - 1;
    long long pos = 1, cc = 1;
    for (long long i = 0; i < c; i++) {
      if ((z) % (cc * 4)) ad += pos * arr[((z) % (cc * 4) + (n + 1 % 3)) % 3];
      pos <<= 2;
      z /= 4;
    }
    cout << ad << endl;
  }
  return 0;
}
