#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG = 20;
long long n, m, k, u, v, x, y, t, a, b, ans;
int Solve() {
  cin >> n;
  if (n <= 4) return cout << n << '\n', 0;
  long long lg = 0;
  while ((1ll << (2 * lg)) <= n) lg++;
  lg--;
  n -= (1ll << (2 * lg));
  int typ = n % 3;
  n /= 3;
  ans = ((typ + 1ll) << (lg * 2));
  for (long long tmp = 1; n; n /= 4, tmp *= 4) {
    if (!typ) ans += tmp * (n % 4);
    if (typ == 1) {
      if (n % 4 == 0) ans += 0 * tmp;
      if (n % 4 == 1) ans += 2 * tmp;
      if (n % 4 == 2) ans += 3 * tmp;
      if (n % 4 == 3) ans += 1 * tmp;
    }
    if (typ == 2) {
      if (n % 4 == 0) ans += 0 * tmp;
      if (n % 4 == 1) ans += 3 * tmp;
      if (n % 4 == 2) ans += 1 * tmp;
      if (n % 4 == 3) ans += 2 * tmp;
    }
  }
  return cout << ans << '\n', 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) Solve();
  return 0;
}
