#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, INF = 1e18;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  for (long long test = 1; test <= t; test++) {
    long long n;
    cin >> n;
    if (n < 4) {
      cout << n << "\n";
      continue;
    }
    long long ans = 3, c1 = 0;
    while (ans < n) {
      ans <<= 2;
      c1 += 2;
      ans |= 3;
    }
    ans >>= 2;
    ans++;
    n -= ans;
    long long temp = n / 3;
    ans += temp;
    n %= 3;
    long long c2 = (3LL << c1);
    temp = 0;
    while (c2) {
      long long c = ans & c2;
      c >>= c1;
      if (c == 0) {
        temp <<= 2;
      } else {
        c--;
        c = (c + n) % 3 + 1;
        temp <<= 2;
        temp |= c;
      }
      c1 -= 2;
      c2 >>= 2;
    }
    cout << temp << "\n";
  }
  return 0;
}
