#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5, MX = 2e5, MN = 0;
long long frstPower4SmallerOrEqual(long long x) {
  long long cur = 1;
  while (cur <= x) {
    cur *= 4;
  }
  return cur / 4;
}
long long getFrst(long long ind) {
  long long frst = ind / 3;
  long long sum = 0;
  long long cur = 1;
  while (sum < frst) {
    cur *= 4;
    sum += cur;
  }
  sum -= cur;
  frst -= sum;
  frst += cur - 1;
  return frst;
}
int getIndInGroup(long long ind) { return (ind - 1) % 3; }
int val[] = {0, 2, 3, 1};
long long getVal(long long x) {
  if (x < 4) return val[x];
  long long pow4 = frstPower4SmallerOrEqual(x);
  int cnt = 0;
  while (x >= pow4) {
    x -= pow4;
    cnt++;
  }
  return val[cnt] * pow4 + getVal(x);
}
long long getScnd(long long frst) {
  long long pow4 = frstPower4SmallerOrEqual(frst);
  return pow4 * 2 + getVal(frst - pow4);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n;
    scanf("%lld", &n);
    if (n <= 3) {
      printf("%lld\n", n);
      continue;
    }
    long long frst = getFrst(n - 1);
    long long scnd = getScnd(frst);
    long long thrd = frst ^ scnd;
    long long ans[] = {frst, scnd, thrd};
    printf("%lld\n", ans[getIndInGroup(n)]);
  }
  return 0;
}
