#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int MOD1 = 998244353;
const long long int N = 2e5 + 5;
const long long int INF = 1000111000111000111LL;
const long double PI = 3.1415926535898;
long long int solve(long long int n) {
  if (n <= 3) {
    return n;
  }
  long long int x = (n - 1) / 3;
  long long int base_id = 0;
  long long int cur = 1;
  for (long long int i = 0;; i++) {
    cur *= 4;
    if ((cur - 1) / 3 <= x) {
      base_id = (cur - 1) / 3;
    } else {
      cur /= 4;
      break;
    }
  }
  long long int base_b = 2 * cur;
  long long int a = cur + x - base_id;
  long long int dif = x - base_id;
  long long int add = 0;
  for (long long int i = 0; i < 61; i += 2) {
    long long int t0 = (1ll << i) & dif;
    long long int t1 = (1ll << (i + 1)) & dif;
    if (t0) t0 = 1;
    if (t1) t1 = 1;
    if (t0 && !t1) add += 2 * pow(4, i / 2);
    if (!t0 && t1) add += 3 * pow(4, i / 2);
    if (t0 && t1) add += pow(4, i / 2);
  }
  long long int b = base_b + add;
  if (n % 3 == 1) return a;
  if (n % 3 == 2)
    return b;
  else
    return a ^ b;
}
int32_t main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int T;
  cin >> T;
  while (T--) {
    long long int n;
    cin >> n;
    long long int ans = solve(n);
    cout << ans << '\n';
  }
  return 0;
}
