#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const vector<int> mods = {998244353, 1000000007, 1000000009};
const long long inf = 3e18;
const double pi = acos(-1.0);
const double eps = 0.0000001;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class... K>
using umap = unordered_map<K...>;
template <class... K>
using uset = unordered_set<K...>;
long long t, n;
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout.precision(13);
  cin >> t;
  for (long long _t = (0); _t < (t); ++_t) {
    cin >> n;
    n--;
    long long c = n / 3;
    long long s = 0;
    long long p4 = 1;
    for (long long i = (0); i < (inf); ++i) {
      if (s + p4 > c) {
        c -= s;
        long long l = p4 + c;
        if (n % 3 == 0) {
          cout << l << "\n";
        } else {
          long long up = n % 3 == 2;
          long long a = (p4 << 1);
          if (up) a ^= p4;
          long long cur = 1;
          while (cur < p4) {
            if (c % 4 == 1) {
              a ^= (cur << 1);
              if (up) a ^= cur;
            }
            if (c % 4 == 2) {
              a ^= cur;
              if (!up) a ^= (cur << 1);
            }
            if (c % 4 == 3) {
              if (up) a ^= cur << 1;
              if (!up) a ^= cur;
            }
            c >>= 2;
            cur <<= 2;
          }
          cout << a << "\n";
        }
        goto outer;
      }
      s += p4;
      p4 *= 4;
    }
  outer:;
  }
  return 0;
}
