#include <bits/stdc++.h>
using namespace std;
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(long long &x, long long y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(long long &x, long long y) { return (y > x) ? x = y, 1 : 0; }
const int N = 100000;
const int inf = (int)1e9 + 1;
const long long big = (long long)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const long double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;
string bin_str(int x) {
  string res;
  while (x) {
    res += char('0' + x % 2);
    x /= 2;
  }
  reverse(res.begin(), res.end());
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  int T;
  cin >> T;
  while (T--) {
    long long x;
    cin >> x;
    x--;
    long long t = x % 3;
    x /= 3;
    for (long long b = 0;; b += 2) {
      if ((1LL << b) <= x) {
        x -= (1LL << b);
        continue;
      }
      long long ans = 0;
      long long pw = 0;
      while (x > 0) {
        long long v = x % 4;
        if (v == 0) {
          v = 0;
        } else {
          v += t;
          if (v > 3) {
            v -= 3;
          }
        }
        ans += (1LL << pw) * v;
        pw += 2;
        x /= 4;
      }
      ans += (t + 1) * (1LL << b);
      cout << ans << "\n";
      break;
    }
  }
  return 0;
}
