#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using ll = long long;
const vector<vector<int>> C = {{0, 1, 2, 3}, {0, 2, 3, 1}, {0, 3, 1, 2}};
int main() {
  ios_base::sync_with_stdio(false);
  int T;
  cin >> T;
  ll n;
  for (int t = 0; t < T; ++t) {
    cin >> n;
    int k = 0;
    while (1LL << (2 * (k + 1)) <= n) ++k;
    ll diff = (n - (1LL << (2 * k))) / 3;
    vector<int> c;
    for (int j = k - 1; j >= 0; --j) {
      c.push_back(diff / (1LL << (2 * j)));
      diff -= c.back() * (1LL << (2 * j));
    }
    ll x = 1LL << (2 * k);
    int mod = (n - 1) % 3;
    x *= mod + 1;
    for (int i = 0, j = k - 1; i < c.size(); --j, ++i) {
      x += C[mod][c[i]] * (1LL << (2 * j));
    }
    cout << x << "\n";
  }
  return 0;
}
