#include <bits/stdc++.h>
using namespace std;
char buf[1ll << 21], *p1 = buf, *p2 = buf, obuf[1ll << 23], *O = obuf;
inline int read() {
  int x = 0, sign = 0;
  char s = getchar();
  while (!isdigit(s)) sign |= s == '-', s = getchar();
  while (isdigit(s)) x = (x << 1ll) + (x << 3) + (s - '0'), s = getchar();
  return sign ? -x : x;
}
void print(int x) {
  if (x > 9) print(x / 10);
  (*O++ = x % 10 + '0');
}
long long n, rem;
long long calc(long long l, long long r, long long num, long long tot) {
  if (l == r) return l;
  if (l == r - 1ll) return l;
  long long sz = (r - l) / 4, a = l + sz, b = l + sz * 2, c = l + sz * 3,
            qwq = tot / 4;
  if (rem == 1ll) {
    if (num <= qwq) return calc(l, a, num, qwq);
    if (num <= qwq * 2) return calc(a, b, num - qwq, qwq);
    if (num <= qwq * 3) return calc(b, c, num - qwq * 2, qwq);
    return calc(c, r, num - qwq * 3, qwq);
  }
  if (rem == 2) {
    if (num <= qwq) return calc(l, a, num, qwq);
    if (num <= qwq * 2) return calc(b, c, num - qwq, qwq);
    if (num <= qwq * 3) return calc(c, r, num - qwq * 2, qwq);
    return calc(a, b, num - qwq * 3, qwq);
  }
  if (rem == 3) {
    if (num <= qwq) return calc(l, a, num, qwq);
    if (num <= qwq * 2) return calc(c, r, num - qwq, qwq);
    if (num <= qwq * 3) return calc(a, b, num - qwq * 2, qwq);
    return calc(b, c, num - qwq * 3, qwq);
  }
}
void solve() {
  cin >> n;
  if (n < 4) {
    cout << n << endl;
    return;
  }
  long long div = (n - 1ll) / 3 + 1ll;
  rem = (n - 1ll) % 3 + 1ll;
  long long bit = -1ll;
  while (n) n >>= 2, bit++;
  cout << calc((rem << (bit * 2)), rem + 1ll << (bit * 2),
               div - ((1ll << (bit * 2)) - 1ll) / 3, 1ll << (bit * 2))
       << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
