#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
long long f[maxn];
long long g[maxn];
int vis[maxn];
int main() {
  f[1] = 1;
  g[1] = 3;
  for (int i = 2;; i++) {
    f[i] = 4 * f[i - 1];
    g[i] = f[i] * 3;
    g[i] += g[i - 1];
    if (g[i] >= 1e16) break;
  }
  for (int i = 1; i <= 1023; i++) {
    for (int j = i + 1; j <= 1023; j++) {
      for (int k = j + 1; k <= 1023; k++) {
        if ((i ^ j ^ k) == 0 && !vis[i] && !vis[j] && !vis[k]) {
          vis[i] = vis[j] = vis[k] = 1;
        }
      }
    }
  }
  int T;
  cin >> T;
  while (T--) {
    long long n;
    cin >> n;
    int id = 0;
    for (int i = 1; i <= 27; i++) {
      if (n <= g[i]) {
        id = i;
        break;
      }
    }
    long long be = f[id];
    if (id == 1) {
      cout << n << endl;
      continue;
    }
    long long pr = g[id - 1] + 1;
    long long a = (n - pr) / 3 + pr, b = 0, c = 0;
    if (n % 3 == 1) {
      cout << a << endl;
    } else if (n % 3 == 2) {
      for (long long i = 0; i < 60; i += 2) {
        long long p = (a >> i) & 1, pp = (a >> (i + 1)) & 1;
        if (!pp && p)
          b += 1ll << (i + 1);
        else if (pp && !p)
          b += (1ll << i) + (1ll << (i + 1));
        else if (pp && p)
          b += 1ll << i;
      }
      cout << b << endl;
    } else {
      for (long long i = 0; i < 60; i += 2) {
        long long p = (a >> i) & 1, pp = (a >> (i + 1)) & 1;
        if (p && pp)
          c += 1ll << (i + 1);
        else if (!pp && p)
          c += (1ll << i) + (1ll << (i + 1));
        else if (pp && !p)
          c += 1ll << i;
      }
      cout << c << endl;
    }
  }
  return 0;
}
