#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return "'" + string(1, c) + "'"; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool f) {
  if (f)
    return "True";
  else
    return "False";
}
string to_string(const char *s) { return to_string((string)s); }
template <typename A>
string to_string(A);
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool f = false;
  string r = "{";
  for (auto x : v) {
    if (f) r += ", ";
    r += to_string(x);
    f = true;
  }
  return r += "}";
}
template <typename A>
string to_string(vector<vector<A>> v) {
  string r;
  for (auto x : v) r += "\n" + to_string(x);
  return r;
}
long long Nerr;
template <typename A>
string to_string(A *p) {
  return to_string(vector<A>(p, p + Nerr));
}
void err(istream_iterator<string>) { cerr << '\n'; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << to_string(a) << "; ";
  err(++it, args...);
}
template <typename T>
void kek(T ans) {
  cout << ans << '\n';
  exit(0);
}
long long count(long long x) {
  long long r = 1, i = 0;
  while (r <= x) {
    i++;
    r = 2 * r;
  }
  i--;
  long long ans = 0;
  for (long long j = 0; j < i + 1; j++) {
    ans += (1ll << j);
    j++;
  }
  if (i % 2 == 0) ans -= (1ll << (i + 1)) - x - 1;
  return ans;
}
long long calc(long long n, long long x) {
  if (n == 1) return 0;
  long long ans = 0;
  if (x < n / 4) ans = calc(n / 4, x);
  if (x >= 3 * n / 4) ans = n / 4 + calc(n / 4, x - 3 * n / 4);
  if (x >= n / 4 and x < n / 2) ans = n / 2 + calc(n / 4, x - n / 4);
  if (x >= n / 2 and x < 3 * n / 4) ans = 3 * n / 4 + calc(n / 4, x - n / 2);
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  long long TESTS = 1;
  cin >> TESTS;
  while (TESTS--) {
    long long n;
    cin >> n;
    if (n <= 3) {
      cout << n << '\n';
      continue;
    }
    long long t = n;
    if (n % 3 == 2) t--;
    if (n % 3 == 0) t -= 2;
    long long lo = 1, hi = 8 * 1e18;
    t = t / 3 + 1;
    while (lo <= hi) {
      long long mid = hi - (hi - lo) / 2;
      if (count(mid) < t)
        lo = mid + 1;
      else
        hi = mid - 1;
    }
    long long a = hi + 1;
    long long r = 1, i = 0;
    while (r <= a) {
      i++;
      r = 2 * r;
    }
    i--;
    long long b = 2 * (1ll << i) + calc((1ll << i), a - (1ll << i));
    long long c = a ^ b;
    if (n % 3 == 1) cout << a << '\n';
    if (n % 3 == 2) cout << b << '\n';
    if (n % 3 == 0) cout << c << '\n';
  }
}
