#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a = (n + 2) / 3;
    long long int ans = 0;
    long long int s = 1;
    if (a == 1) {
      ans = n;
    } else {
      while (a > s) {
        a -= s;
        s *= 4;
      }
      string v = "";
      a += (s - 1);
      long long int t = a;
      while (t > 0) {
        if (t % 2 == 0)
          v += '0';
        else
          v += '1';
        t /= 2;
      }
      long long int rem = (n + 2) % 3;
      if (rem == 0) {
        ans = a;
      } else if (rem == 1) {
        int sz = v.size();
        reverse(v.begin(), v.end());
        string tp, sp;
        for (int i = 1; i < sz; i += 2) {
          tp = v.substr(i, 2);
          sp = "00";
          if (tp == "01")
            sp = "10";
          else if (tp == "10")
            sp = "11";
          else if (tp == "11")
            sp = "01";
          v.replace(i, 2, sp);
        }
      } else if (rem == 2) {
        int sz = v.size();
        reverse(v.begin(), v.end());
        for (int i = 1; i < sz; i += 2) {
          string tp = v.substr(i, 2);
          string sp = "00";
          if (tp == "01")
            sp = "11";
          else if (tp == "10")
            sp = "01";
          else if (tp == "11")
            sp = "10";
          v.replace(i, 2, sp);
        }
      }
      if (rem != 0) {
        long long int p = 1;
        reverse(v.begin(), v.end());
        for (auto x : v) {
          if (x == '1') {
            ans += p;
          }
          p *= 2;
        }
        ans += s;
        if (rem == 2) {
          ans += s;
        }
      }
    }
    cout << ans << "\n";
  }
}
