#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int four[28], two[56];
  four[0] = 1;
  two[0] = 1;
  for (int i = 1; i <= 27; i++) four[i] = four[i - 1] * 4;
  for (int i = 1; i <= 55; i++) two[i] = two[i - 1] * 2;
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int req = (n + 2) / 3;
    long long int rem = n % 3;
    int index = 0;
    while ((four[index + 1] - 1) / 3 < req) index++;
    long long int ans = four[index];
    if (rem == 1)
      ans = ans;
    else if (rem == 2)
      ans = ans * 2;
    else
      ans = ans * 3;
    req = req - (four[index] - 1) / 3;
    int count = 0;
    while (req) {
      int x = req % 4;
      if (x == 0) {
        if (rem == 0)
          ans += four[count] * 2;
        else if (rem == 1)
          ans += four[count] * 3;
        else
          ans += four[count] * 1;
      } else if (x == 1) {
        ans = ans;
      } else if (x == 2) {
        if (rem == 0)
          ans += four[count] * 3;
        else if (rem == 1)
          ans += four[count] * 1;
        else
          ans += four[count] * 2;
      } else {
        if (rem == 0)
          ans += four[count] * 1;
        else if (rem == 1)
          ans += four[count] * 2;
        else
          ans += four[count] * 3;
      }
      if (req == 1) break;
      req = (req + 3) / 4;
      count++;
    }
    cout << ans << "\n";
  }
  return 0;
}
