#include <bits/stdc++.h>
using namespace std;
long long a[100010];
long long pow(long long x, long long y, long long k) {
  long long res = 1;
  while (y) {
    if (y & 1) res *= x;
    res = res % k;
    if (x > 1e9) break;
    x *= x;
    x = x % k;
    y = y >> 1;
  }
  return res;
}
long long c[200];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n;
    scanf("%lld", &n);
    long long o = 0, res = 1, ans = 0;
    long long now = 0;
    while (((pow(4, o + 1, 1e18) - 1) / 3) * 3 < n) {
      o++;
    }
    o--;
    long long m;
    m = n - ((pow(4, o + 1, 1e18) - 1) / 3) * 3;
    long long p = (m - 1) / 3, pmod = m % 3;
    if (pmod == 0) pmod = 3;
    ans += (pmod << 2 * (o + 1));
    long long flag = p % 4;
    o = 0;
    while (p > 0) {
      c[o] = p % 4;
      o++;
      p = p / 4;
    }
    for (long long i = 0; i < o; i++) {
      if (c[i] != 0) {
        c[i] = (long long)(c[i] + pmod - 1) % 3;
        if (c[i] == 0) c[i] = 3;
      }
      ans += ((long long)c[i] << (long long)(2 * i));
    }
    printf("%lld\n", ans);
  }
}
