#include <bits/stdc++.h>
inline __attribute__((always_inline)) void init_io() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::fixed(std::cout).precision(10);
}
template <typename... Args>
inline __attribute__((always_inline)) bool read(Args&... args) {
  return (bool)(std::cin >> ... >> args);
}
template <typename... Args>
inline __attribute__((always_inline)) void write(Args&&... args) {
  (std::cout << ... << std::forward<Args>(args));
}
template <class... Args>
inline __attribute__((always_inline)) void writeln(Args&&... args) {
  write(std::forward<Args>(args)..., '\n');
}
inline __attribute__((always_inline)) void flush() { std::flush(std::cout); }
constexpr int8_t operator""_i8(unsigned long long val) { return val; }
constexpr uint8_t operator""_u8(unsigned long long val) { return val; }
constexpr int16_t operator""_i16(unsigned long long val) { return val; }
constexpr uint16_t operator""_u16(unsigned long long val) { return val; }
constexpr int32_t operator""_i32(unsigned long long val) { return val; }
constexpr uint32_t operator""_u32(unsigned long long val) { return val; }
constexpr int64_t operator""_i64(unsigned long long val) { return val; }
constexpr uint64_t operator""_u64(unsigned long long val) { return val; }
uint64_t digits[4][3] = {
    {0, 0, 0},
    {1, 2, 3},
    {2, 3, 1},
    {3, 1, 2},
};
uint64_t solve(uint64_t n) {
  uint64_t abc = n % 3;
  n /= 3;
  unsigned num_cnt = 0;
  while (n >= (1_u64 << (2 * num_cnt))) {
    n -= (1_u64 << (2 * num_cnt));
    num_cnt += 1;
  }
  uint64_t res = digits[1][abc] << (2 * num_cnt);
  for (unsigned i = 0; i < num_cnt; ++i) {
    unsigned part = n % 4;
    n /= 4;
    res |= (digits[part][abc]) << (2 * i);
  }
  return res;
}
int main() {
  init_io();
  int t;
  read(t);
  while (t-- > 0) {
    uint64_t n;
    read(n);
    writeln(solve(n - 1));
  }
  return 0;
}
