#include <bits/stdc++.h>
using namespace std;
long long digit[500050];
long long loop[3][4] = {{0, 1, 2, 3}, {0, 2, 3, 1}, {0, 3, 1, 2}};
long long step[50];
int main() {
  int t;
  cin >> t;
  step[0] = 1;
  for (long long i = 1; i <= 26; i++) step[i] = step[i - 1] * 4;
  while (t--) {
    for (int i = 0; i <= 50; i++) digit[i] = 0;
    long long n;
    scanf("%lld", &n);
    long long tmp = n;
    long long cur = 0;
    long long cnt = 0;
    while (cur + 3ll * pow(4, cnt) < n) cur += 3ll * pow(4, cnt), cnt++;
    n -= step[cnt] - 1;
    for (int i = cnt - 1; i >= 0; i--) {
      long long cur = 3ll * step[i];
      digit[i] = (n ? n - 1 : 0) / cur;
      n = n % cur + cur * (n % cur == 0);
    }
    long long res = 0;
    int flag = (tmp + 2) % 3;
    res += 1ll * ((tmp + 2) % 3 + 1) * pow(4, cnt);
    for (long long i = cnt - 1; i >= 0; i--) {
      res += step[i] * loop[flag][digit[i]];
    }
    cout << res << endl;
  }
}
