#include <bits/stdc++.h>
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 2e5 + 10;
bool visit[maxn];
string getFour(long long x) {
  string ret = "";
  while (x) {
    ret += '0' + x % 4;
    x /= 4;
  }
  reverse(ret.begin(), ret.end());
  return ret;
}
void print(string x) {
  reverse(x.begin(), x.end());
  long long cur = 1;
  long long ret = 0;
  for (int i = 0; i < x.length(); i++) {
    ret += (x[i] - '0') * cur;
    cur *= 4ll;
  }
  cout << ret << " ";
  return;
}
int main() {
  int cas;
  cin >> cas;
  long long t1;
  string a, b, c;
  while (cas--) {
    a = b = c = "";
    cin >> t1;
    long long tmpt = t1;
    t1 = (t1 + 2ll) / 3ll;
    long long cur = 1;
    while (true) {
      if (t1 <= cur) break;
      t1 -= cur;
      cur *= 4ll;
    }
    a = getFour(cur + t1 - 1ll);
    for (int i = 0; i < a.length(); i++) {
      if (a[i] == '0') {
        b += "0";
        c += "0";
      } else {
        int t = a[i] - '0';
        if (t == 1) {
          b += "2";
          c += "3";
        } else if (t == 2) {
          b += "3";
          c += "1";
        } else {
          b += "1";
          c += "2";
        }
      }
    }
    if (tmpt % 3ll == 1ll)
      print(a);
    else if (tmpt % 3ll == 2)
      print(b);
    else
      print(c);
    cout << endl;
  }
  return 0;
}
