#include <bits/stdc++.h>
using namespace std;
template <typename T>
void UpdateMax(T& a, T b) {
  if (a < b) a = b;
}
template <typename T>
void UpdateMin(T& a, T b) {
  if (a > b) a = b;
}
template <typename T>
inline void read(T& x) {
  x = 0;
  char c = getchar();
  int flag = 1;
  while (!isdigit(c)) {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= flag;
}
template <typename T>
void Unique(vector<T>& vec) {
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
}
template <typename T>
void Relabel(vector<T>& vec, T& value) {
  value = lower_bound(vec.begin(), vec.end(), value) - vec.begin() + 1;
}
template <typename T, typename V>
void Print(const pair<T, V>& x) {
  cout << x.first << " @ " << x.second << " | ";
}
template <typename T>
void Print(const T& x) {
  cout << x << " ";
}
template <typename T>
void Pcon(const T& x) {
  cout << "\nsize: " << x.size() << endl;
  for (const auto& item : x) Print(item);
}
std::vector<int> LABS;
template <typename T>
void Print(const T* x, int offset, int loop) {
  for (int i = 0; i <= loop; i++) {
    cout << "[";
    for (int item : LABS) cout << item - offset << ",";
    cout << i - offset << "]:";
    cout << x[i] << " ";
  }
}
template <typename T, typename... Args>
void Print(const T* f, int offset, int loop, Args... args) {
  for (int i = 0; i <= loop; i++) {
    LABS.push_back(i);
    Print(f[i], offset, args...);
    cout << endl;
    LABS.pop_back();
  }
}
clock_t start_time;
inline void SetClock() { start_time = clock(); }
bool TimeOut(size_t ms) {
  if (1000 * (clock() - start_time) >= ms * ((clock_t)1000)) return true;
  return false;
}
int T;
long long n;
long long FetchGroup(long long x) {
  long long cnt = 0;
  while (1ll << (cnt << 1) <= x) {
    ++cnt;
  }
  return 1ll << ((--cnt) << 1);
}
long long FetchReverse(long long x) {
  long long ret = 0, cnt = 0;
  while (x) {
    long long res = x & 3;
    if (res == 1) {
      res = 2;
    } else if (res == 2) {
      res = 3;
    } else if (res == 3) {
      res = 1;
    }
    ret += res << cnt;
    cnt += 2;
    x >>= 2;
  }
  return ret;
}
int main() {
  srand(time(0));
  SetClock();
  cin.sync_with_stdio(false);
  cin >> T;
  while (T--) {
    cin >> n;
    auto col = n % 3 ? n % 3 : 3;
    auto group = FetchGroup(n);
    auto rowInGroup = (n - group) / 3;
    auto second = FetchReverse(group + rowInGroup);
    if (col == 1) {
      cout << group + rowInGroup << endl;
    } else if (col == 2) {
      cout << second << endl;
    } else {
      cout << (second ^ (group + rowInGroup)) << endl;
    }
  }
}
