#include <bits/stdc++.h>
using namespace std;
const long long SZ = 1e5 + 4;
const double EPS = 1e-7;
const long long mod = 1e9 + 7;
const long long hashpow = 2;
const long long inf = 2e9;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
long long n;
void read() {
  cin >> n;
  --n;
}
void solve() {
  long long x = 1;
  long long m = n % 3;
  n /= 3;
  long long cnt = 0;
  while (n >= x) {
    n -= x;
    x *= 4;
    ++cnt;
  }
  long long a = 1;
  long long b = 2;
  long long c = 3;
  vector<long long> y;
  while (n) {
    y.push_back(n % 4);
    n /= 4;
  }
  while (y.size() < cnt) {
    y.push_back(0);
  }
  for (long long i = (long long)(y.size()) - 1; i >= 0; --i) {
    a *= 4;
    b *= 4;
    c *= 4;
    if (y[i] == 1) {
      a += 1;
      b += 2;
      c += 3;
    } else if (y[i] == 2) {
      a += 2;
      b += 3;
      c += 1;
    } else if (y[i] == 3) {
      a += 3;
      b += 1;
      c += 2;
    }
  }
  if (m == 0) {
    cout << a << "\n";
  } else if (m == 1) {
    cout << b << "\n";
  } else {
    cout << c << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  for (long long i = 0; i < t; ++i) {
    read();
    solve();
  }
  return 0;
}
