#include <bits/stdc++.h>
using namespace std;
vector<int> seq, seq2, seq3;
set<int> s, s2, s3;
void process() {
  int max = 1;
  for (int i = 0; i < 16; i += 3) {
    for (int e = max; e < 300; e++) {
      if (s.count(e)) continue;
      seq.push_back(e);
      s.insert(e);
      max = e + 1;
      int j = e + 1;
      while (s.count(j) || s.count(e ^ j)) j++;
      seq.push_back(j);
      seq.push_back(e ^ j);
      s.insert(j);
      s.insert(e ^ j);
      break;
    }
  }
}
bool a[100000], a2[100000] = {0}, a3[100000] = {0};
void process2(int N) {
  int p = 4;
  int max = 0;
  int p1 = 0;
  int p2 = 0;
  int p3 = 0;
  for (int i = 0; i < N; i++) {
    seq.push_back((i / 16) * 16);
    s.insert(i);
    for (int e = 0; e < N * N; e++) {
      if (s2.count(e) || s3.count(i ^ e)) continue;
      seq2.push_back((e) & ((1 << 20) - 1 - 15));
      seq3.push_back((e & 15));
      s2.insert(e);
      a2[e] = true;
      s3.insert(e ^ i);
      a3[e ^ i] = true;
      break;
    }
    if (i + 1 == (1 << p)) {
      bool good = true;
      for (int e = 0; e <= i; e++) {
        good = good & a2[e] & a3[e];
      }
      if (good) cout << p << endl;
      p *= 2;
      max = (1 << p);
    }
  }
  cout << (243 & 15) << endl;
  for (int i = 0; i < N; i++) {
    if (i % 15 == 0) cout << endl;
    cout << seq[i] << " " << seq2[i] << " " << seq3[i] << endl;
  }
}
long long add;
long long row;
long long col;
long long arr[16][3];
long long find(long long row, long long col) {
  long long ans = 0;
  if (row >= 16) {
    ans += 16 * find(row / 16, col);
    row = row % 16;
  }
  return ans + arr[row][col];
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < 16; i++) {
    arr[i][0] = i;
    s.insert(i);
    for (int e = 0; e < 300; e++) {
      if (s2.count(e) || s3.count(i ^ e)) continue;
      arr[i][1] = e;
      arr[i][2] = e ^ i;
      s2.insert(e);
      a2[e] = true;
      s3.insert(e ^ i);
      a3[e ^ i] = true;
      break;
    }
  }
  s.clear();
  process();
  for (int i = 0; i < t; i++) {
    long long N;
    cin >> N;
    add = 16;
    if (N < 16) {
      N--;
      cout << seq[N] << endl;
      continue;
    }
    while (add * 4 <= N) {
      add *= 4;
    }
    N -= add;
    row = N / 3;
    col = N % 3;
    if (N % 3 == 1) {
      add *= 2;
    } else if (N % 3 == 2) {
      add *= 3;
    }
    long long ans = add + find(row, col);
    cout << ans << endl;
  }
  return 0;
}
