#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int T = 0; T < t; ++T) {
    long long n;
    cin >> n;
    n--;
    int cs = n % 3;
    n /= 3;
    if (n == 0) {
      cout << cs + 1 << "\n";
      continue;
    }
    long long res = 0, i = 0;
    for (; n > 0; n >>= 2, ++i) {
      n--;
      long long toAdd;
      int cur = n % 4;
      if (cs == 0) {
        toAdd = cur;
      } else if (cs == 1) {
        if (cur == 0) {
          toAdd = 0;
        } else if (cur == 1) {
          toAdd = 2;
        } else if (cur == 2) {
          toAdd = 3;
        } else {
          toAdd = 1;
        }
      } else {
        if (cur == 0) {
          toAdd = 0;
        } else if (cur == 1) {
          toAdd = 3;
        } else if (cur == 2) {
          toAdd = 1;
        } else {
          toAdd = 2;
        }
      }
      res += toAdd << (2 * i);
    }
    if (cs == 0) {
      res += 1ll << (2 * i);
    } else if (cs == 1) {
      res += 2ll << (2 * i);
    } else {
      res += 3ll << (2 * i);
    }
    cout << res << "\n";
  }
}
