#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
ifstream in("input.txt");
ofstream out("output.txt");
pair<long long, long long> bc(long long a) {
  vector<int> b, c;
  while (a > 0) {
    int cur = a % 4;
    if (cur == 0) {
      b.push_back(0);
      c.push_back(0);
    } else {
      b.push_back((cur % 3) + 1);
      c.push_back(((cur + 1) % 3) + 1);
    }
    a /= 4;
  }
  long long B = 0, C = 0, POW = 1;
  for (int i = 0; i < b.size(); i++) {
    B += POW * b[i];
    POW *= 4;
  }
  POW = 1;
  for (int i = 0; i < c.size(); i++) {
    C += POW * c[i];
    POW *= 4;
  }
  return {B, C};
}
int main() {
  vector<long long> pref = {0};
  for (int p = 0; pref.back() < 1e16; p += 2)
    pref.push_back((1LL << p) + pref.back());
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long tr = (n + 2) / 3;
    long long bl = lower_bound(pref.begin(), pref.end(), tr) - pref.begin();
    long long a = (1LL << 2 * (bl - 1)) + tr - pref[bl - 1] - 1;
    pair<long long, long long> cur = bc(a);
    long long d = (n - 1) % 3;
    if (d == 0)
      cout << a;
    else if (d == 1)
      cout << cur.first;
    else
      cout << cur.second;
    cout << '\n';
  }
}
