#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6;
void dfs1(long long bg, long long ed, long long n) {
  if (n == 1) {
    cout << bg << "\n";
    return;
  }
  long long pr = (ed - bg + 1) / 4;
  if (n <= pr)
    dfs1(bg, bg + pr - 1, n);
  else if (n <= pr + pr)
    dfs1(bg + pr + pr, bg + pr + pr + pr - 1, n - pr);
  else if (n <= pr + pr + pr)
    dfs1(bg + pr + pr + pr, bg + pr + pr + pr + pr - 1, n - pr - pr);
  else
    dfs1(bg + pr, bg + pr + pr - 1, n - pr - pr - pr);
}
void dfs2(long long bg, long long ed, long long n) {
  if (n == 1) {
    cout << bg << "\n";
    return;
  }
  long long pr = (ed - bg + 1) / 4;
  if (n <= pr)
    dfs2(bg, bg + pr - 1, n);
  else if (n <= pr + pr)
    dfs2(bg + pr + pr + pr, bg + pr + pr + pr + pr - 1, n - pr);
  else if (n <= pr + pr + pr)
    dfs2(bg + pr, bg + pr + pr - 1, n - pr - pr);
  else
    dfs2(bg + pr + pr, bg + pr + pr + pr - 1, n - pr - pr - pr);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    if (n % 3 == 1) {
      n /= 3;
      n++;
      for (long long i = 0;; i += 2) {
        long long cn = (1LL << i);
        if (n > cn)
          n -= cn;
        else {
          cout << cn + n - 1 << endl;
          break;
        }
      }
    } else if (n % 3 == 2) {
      n /= 3;
      n++;
      for (long long i = 0;; i += 2) {
        long long cn = (1LL << i);
        if (n > cn)
          n -= cn;
        else {
          dfs1(cn + cn, cn + cn + cn - 1, n);
          break;
        }
      }
    } else {
      n /= 3;
      for (long long i = 0;; i += 2) {
        long long cn = (1LL << i);
        if (n > cn)
          n -= cn;
        else {
          dfs2(cn + cn + cn, cn + cn + cn + cn - 1, n);
          break;
        }
      }
    }
  }
  return 0;
}
