#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
namespace {
template <class U, class V>
std::istream &operator>>(std::istream &is, std::pair<U, V> &p);
template <class U, class V>
std::ostream &operator<<(std::ostream &os, const std::pair<U, V> &p);
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &xs);
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &xs);
}  // namespace
namespace io {
template <class... Args>
void err(const std::string &args_str, const Args &...args);
template <class... Args>
void read(Args &...args);
}  // namespace io
using i64 = int64_t;
using u64 = uint64_t;
template <class T>
using Vec = std::vector<T>;
template <class K, class H = std::hash<K>>
using US = std::unordered_set<K, H>;
template <class K, class V, class H = std::hash<K>>
using UM = std::unordered_map<K, V, H>;
using namespace std;
template <class L, class R, class F>
auto bin_search(L left, R right, F func) -> std::common_type<L, R> {
  using T = std::common_type<L, R>;
  T l = left, r = right;
  for (T m; m = (l + r) / 2, m != l && m != r;) {
    (func(m) ? l : r) = m;
  }
  return l;
}
template <class T>
T &upd_min(T &lhs, const T &rhs) {
  return lhs = std::min(lhs, rhs);
}
template <class T>
T &upd_max(T &lhs, const T &rhs) {
  return lhs = std::max(lhs, rhs);
}
i64 get1(i64 n, i64 log) { return (n - (1ll << log)) / 3 + (1ll << log); }
i64 unget1(i64 n, i64 log) { return (1ll << log) + (n - (1ll << log)) * 3; }
i64 get2(i64 n, i64 log) {
  i64 prev = get1(n - 1, log);
  prev ^= (1ll << log) ^ (1ll << (log + 1));
  for (int llog = 0; llog < log; llog += 2) {
    if ((prev & (3ll << llog)) == (0ll << llog)) {
      prev ^= 0ll << llog;
      continue;
    }
    if ((prev & (3ll << llog)) == (1ll << llog)) {
      prev ^= 3ll << llog;
      continue;
    }
    if ((prev & (3ll << llog)) == (2ll << llog)) {
      prev ^= 1ll << llog;
      continue;
    }
    if ((prev & (3ll << llog)) == (3ll << llog)) {
      prev ^= 2ll << llog;
      continue;
    }
  }
  return prev;
}
i64 unget2(i64 n, i64 log) {
  i64 prev = n ^ (1ll << log) ^ (1ll << (log + 1));
  switch (prev & 3ll) {
    case 0:
      return unget1(prev, log) + 1;
    case 1:
      return unget1(prev ^ 2ll, log) + 1;
    case 2:
      return unget2(prev ^ 3ll, log) + 1;
    case 3:
      return unget2(prev ^ 1ll, log) + 1;
  }
}
i64 get3(i64 n, i64 log) { return get1(n - 2, log) ^ get2(n - 1, log); }
i64 unget3(i64 n, i64 log) {
  i64 prev = n ^ (1ll << (log + 1));
  switch (prev & 3ll) {
    case 0:
      return unget1(prev, log) + 2;
    case 1:
      return unget1(prev ^ 3ll, log) + 2;
    case 2:
      return unget2(prev ^ 1ll, log) + 2;
    case 3:
      return unget2(prev ^ 2ll, log) + 2;
  }
}
i64 get(i64 n, i64 log) {
  if (n < 4) return n;
  if (n % 3 == 1) return get1(n, log);
  if (n % 3 == 2) return get2(n, log);
  if (n % 3 == 0) return get3(n, log);
}
i64 unget(i64 n, i64 log) {
  if (n < 4) return n;
  if (n & (3ll << log) == (1ll << log)) return unget1(n, log);
  if (n & (3ll << log) == (2ll << log)) return unget2(n, log);
  if (n & (3ll << log) == (3ll << log)) return unget3(n, log);
}
auto main() -> int {
  int t;
  io::read(t);
  ;
  while (t--) {
    i64 n;
    io::read(n);
    ;
    i64 bit = 1, log = 0;
    for (; (bit << 1) <= n; ++log, bit <<= 1)
      ;
    log -= log % 2;
    cout << get(n, log) << '\n';
  }
}
namespace io {
template <typename It>
void err(It) {
  std::cerr << std::endl;
}
template <typename It, typename T>
void err(It it, const T &a) {
  std::cerr << *it << " = " << a;
  err(++it);
}
template <typename It, typename T, typename... Args>
void err(It it, const T &a, const Args &...args) {
  std::cerr << *it << " = " << a << ",";
  err(++it, args...);
}
std::vector<std::string> split(const std::string &s, char c) {
  std::vector<std::string> v;
  std::stringstream ss(s);
  std::string x;
  while (std::getline(ss, x, c)) v.emplace_back(x);
  return v;
}
template <class... Args>
void err(const std::string &args_str, const Args &...args) {
  auto args_var = split(args_str, ',');
  err(args_var.begin(), args...);
}
auto fast_io = [] {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  return 0;
}();
template <class Arg, class... Rest>
void read(Arg &arg, Rest &...rest) {
  std::cin >> arg;
  read(rest...);
}
template <>
void read() {}
template <class... Args>
void read(Args &...args) {
  read(args...);
}
}  // namespace io
namespace {
template <class U, class V>
std::istream &operator>>(std::istream &is, std::pair<U, V> &p) {
  return is >> p.first >> p.second;
}
template <class U, class V>
std::ostream &operator<<(std::ostream &os, const std::pair<U, V> &p) {
  return os << p.first << " " << p.second;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &xs) {
  for (auto &x : xs) is >> x;
  return is;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &xs) {
  if (xs.empty()) return os;
  auto it = xs.begin();
  for (os << *it++; it != xs.end(); ++it) {
    os << " " << *it;
  }
  return os;
}
}  // namespace
