#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (auto i = begin(v); i != end(v); i++)
    os << *i << (i == end(v) - 1 ? "" : " ");
  return os;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto i = begin(v); i != end(v); i++) is >> *i;
  return is;
}
long long recur(pair<long long, long long> a, pair<long long, long long> b,
                pair<long long, long long> c, long long nth) {
  if (a.second == a.first) {
    if (nth == 0) return a.first;
    if (nth == 1) return b.first;
    return c.first;
  }
  long long step = (a.second - a.first + 1LL) / 4LL;
  if (nth < step * 3LL) {
    return recur({a.first, a.first + step - 1LL},
                 {b.first, b.first + step - 1LL},
                 {c.first, c.first + step - 1LL}, nth);
  } else if (nth < step * 6LL) {
    return recur({a.first + step, a.first + 2LL * step - 1LL},
                 {b.first + step * 2LL, b.first + 3LL * step - 1LL},
                 {c.first + step * 3LL, c.first + 4LL * step - 1LL},
                 nth - step * 3LL);
  } else if (nth < step * 9LL) {
    return recur({a.first + step * 2LL, a.first + 3LL * step - 1LL},
                 {b.first + 3LL * step, b.first + 4LL * step - 1LL},
                 {c.first + step, c.first + 2LL * step - 1LL},
                 nth - step * 6LL);
  } else {
    return recur({a.first + step * 3LL, a.first + 4LL * step - 1LL},
                 {b.first + step, b.first + 2LL * step - 1LL},
                 {c.first + step * 2LL, c.first + 3LL * step - 1LL},
                 nth - step * 9LL);
  }
}
long long find_nth(long long n) {
  for (long long i = 0; i < 58; i += 2) {
    long long start = 1LL << i;
    long long end = start * 4LL - 1;
    if (n >= start && n <= end) {
      return recur({start, start * 2LL - 1LL}, {start * 2LL, start * 3LL - 1LL},
                   {start * 3LL, end}, n - start);
    }
  }
  throw 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    cout << find_nth(x) << "\n";
  }
  return 0;
}
