#include <bits/stdc++.h>
using namespace std;
long long p[35], sum[35];
int main() {
  p[0] = 1;
  sum[0] = 1;
  for (int i = 1; i <= 31; i++) p[i] = p[i - 1] * 4;
  for (int i = 1; i <= 31; i++) {
    sum[i] = sum[i - 1] + p[i];
  }
  int t;
  cin >> t;
  while (t--) {
    long long n;
    scanf("%lld", &n);
    long long mo = n % 3;
    n = n / 3;
    if (mo) n++;
    if (n == 1) {
      if (mo == 1)
        printf("1\n");
      else if (mo == 2)
        printf("2\n");
      else
        printf("3\n");
    } else {
      for (int i = 0; i <= 30; i++) {
        if (sum[i + 1] >= n && n > sum[i]) {
          long long x = n - sum[i];
          long long st, ed;
          x--;
          st = p[i + 1];
          ed = st + x;
          long long ans = 0;
          long long cnt = 0;
          while (x) {
            if (x % 4 == 1) {
              ans += 2 * (1ll << cnt);
            } else if (x % 4 == 2) {
              ans += 2 * (1ll << cnt);
              ans += (1ll << cnt);
            } else if (x % 4 == 3) {
              ans += (1ll << cnt);
            }
            x /= 4;
            cnt += 2;
          }
          ans += p[i + 1] * 2ll;
          if (mo == 1) {
            printf("%lld\n", ed);
          } else if (mo == 2) {
            printf("%lld\n", ans);
          } else {
            printf("%lld\n", ed ^ ans);
          }
          break;
        }
      }
    }
  }
}
