#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long findFirstElement = n;
    if (n % 3 == 0)
      findFirstElement -= 2;
    else if (n % 3 == 2)
      findFirstElement--;
    long long lg = (long long)log2(findFirstElement);
    if (lg % 2 == 1) lg--;
    long long pw = (long long)pow(2, lg);
    long long become = pw + (findFirstElement - pw) / 3;
    if (findFirstElement == n) {
      cout << become << endl;
      continue;
    }
    long long becomeSecond = pw * 2ll, wat = pw;
    for (; pw;) {
      if (wat + pw / 4 > become)
        ;
      else if (wat + pw / 2 > become)
        wat = wat + pw / 4, becomeSecond += pw / 2;
      else if (wat + 3 * pw / 4 > become)
        wat = wat + pw / 2, becomeSecond += 3 * pw / 4;
      else
        becomeSecond += pw / 4, wat = wat + 3 * pw / 4;
      pw /= 4;
    }
    if (n % 3 == 2)
      cout << becomeSecond << endl;
    else
      cout << (becomeSecond ^ become) << endl;
  }
  return 0;
}
