#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    if (n <= 3) {
      cout << n << '\n';
      continue;
    }
    long long pos = (n + 2) / 3;
    long long a, b, c;
    long long num = 1;
    long long curr = 0;
    while (curr < pos) {
      curr += num;
      num *= 4;
    }
    num /= 4;
    curr -= num;
    long long q = pos - curr - 1;
    a = (num + q);
    long long zz = 0;
    curr = 1;
    while (curr <= q) {
      long long pp = (q / curr);
      pp = (pp % 4);
      if (pp == 1) zz |= 2 * curr;
      if (pp == 2) zz |= 3 * curr;
      if (pp == 3) zz |= curr;
      curr *= 4;
    }
    b = (2 * num + zz);
    c = a ^ b;
    if (n % 3 == 0) {
      cout << c << '\n';
    }
    if (n % 3 == 1) {
      cout << a << '\n';
    }
    if (n % 3 == 2) {
      cout << b << '\n';
    }
  }
}
