#include <bits/stdc++.h>
using namespace std;
long long ord[3][4] = {{0, 1, 2, 3}, {0, 2, 3, 1}, {0, 3, 1, 2}};
long long cor[1005];
long long ans(long long iter, long long mod) {
  if (!iter) return mod + 1;
  long long x = (iter - 1) % 4;
  long long tmp = ans((iter - 1) / 4, mod) * 4 + ord[mod][x];
  return tmp;
}
signed main() {
  long long t, x;
  cin >> t;
  while (t--) {
    cin >> x;
    long long iter = (x - 1) / 3, mod = (x - 1) % 3;
    cout << ans(iter, mod) << '\n';
  }
}
