#include <bits/stdc++.h>
using namespace std;
long long n;
long long temp1, temp2, temp3;
void runFree() {
  vector<int> adj;
  for (int i = 1; i <= n; i++) {
    adj.push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    adj.push_back(n - i + 1);
  }
}
void solve() {
  temp1 = 0, temp2 = 0, temp3 = 0;
  int leftmost = 0;
  while (temp1 < n) temp1 += (1LL << leftmost) * 3, leftmost += 2;
  leftmost -= 2;
  temp1 -= (1ll << leftmost) * 3;
  temp1 = (1LL << leftmost) + (n - temp1 - 1) / 3ll;
  leftmost += 1;
  for (int i = leftmost; i >= 0; i -= 2) {
    int b1 = (temp1 >> (long long)(i)&1LL);
    int b2 = (temp1 >> (long long)(i - 1) & 1LL);
    int val = ((b1 << 1) + b2);
    temp2 <<= 2LL;
    temp3 <<= 2LL;
    if (val == 1) temp2 += 2, temp3 += 3;
    if (val == 2) temp2 += 3, temp3 += 1;
    if (val == 3) temp2 += 1, temp3 += 2;
  }
}
int main() {
  int TC;
  cin >> TC;
  while (TC--) {
    cin >> n;
    solve();
    if (n % 3 == 1) cout << temp1;
    if (n % 3 == 2) cout << temp2;
    if (n % 3 == 0) cout << temp3;
    cout << '\n';
  }
}
