#include <bits/stdc++.h>
using namespace std;
string bit(int n) {
  string ans;
  while (n) {
    ans.push_back((n % 2) + '0');
    n /= 2;
  }
  while (ans.size() < 8) {
    ans.push_back('0');
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
void solve(long long n) {
  --n;
  long long pos = n / 3;
  if (pos == 0) {
    cout << n + 1 << "\n";
    return;
  }
  string arr[3];
  pos--;
  int len = 1;
  for (int i = 1; pow(4, i) <= pos; i++) {
    len++;
    pos -= pow(4, i);
  }
  vector<int> mod;
  while (pos) {
    mod.push_back(pos % 4);
    pos /= 4;
  }
  while (mod.size() < len) {
    mod.push_back(0);
  }
  mod.push_back(1);
  reverse(mod.begin(), mod.end());
  for (auto& poss : mod) {
    if (poss % 4 == 0) {
      arr[0] += "00";
      arr[1] += "00";
      arr[2] += "00";
    } else if (poss % 4 == 1) {
      arr[0] += "01";
      arr[1] += "10";
      arr[2] += "11";
    } else if (poss % 4 == 2) {
      arr[0] += "10";
      arr[1] += "11";
      arr[2] += "01";
    } else {
      arr[0] += "11";
      arr[1] += "01";
      arr[2] += "10";
    }
    pos /= 4;
  }
  long long ans = 0;
  reverse(arr[n % 3].begin(), arr[n % 3].end());
  for (int j = 0; j < arr[n % 3].size(); j++) {
    if (arr[n % 3][j] == '1') {
      ans += 1LL << j;
    }
  }
  cout << "" << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin.sync_with_stdio(0);
  cout.tie(0);
  cout.sync_with_stdio(0);
  cout.precision(9);
  int q;
  cin >> q;
  while (q--) {
    long long n;
    cin >> n;
    solve(n);
  }
  return 0;
}
