#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
vector<long long> num;
long long gcd(long long x, long long y) {
  if (y > x) return gcd(y, x);
  return x % y ? gcd(y, x % y) : y;
}
int a[3];
vector<vector<int> > grid;
vector<vector<int> > dist;
void bfs(int x, vector<bool>& vis) {
  int n = vis.size();
  queue<int> q;
  q.push(a[x]);
  vis[a[x]] = 1;
  dist[a[x]][x] = 0;
  int step = 1;
  while (q.size()) {
    int t = q.size();
    while (t--) {
      int tmp = q.front();
      q.pop();
      for (int i = 0; i < grid[tmp].size(); i++) {
        int next = grid[tmp][i];
        if (!vis[next]) {
          dist[next][x] = step;
          vis[next] = 1;
          q.push(next);
        }
      }
    }
    step++;
  }
  return;
}
long long shu[63];
int find(long long x) {
  for (int i = 0; i < 63; i++) {
    if (shu[i] >= x) return i;
  }
  return 63;
}
long long zhuan(string s) {
  int n = s.size();
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans = ans * 2 + (long long)(s[i] - '0');
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  while (n--) {
    long long t;
    cin >> t;
    t--;
    long long pos = t % 3;
    t = t / 3;
    long long sum = 1;
    int cnt = 1;
    while (sum <= t) {
      t -= sum;
      sum *= 4;
      cnt += 2;
    }
    string ans = "";
    if (pos == 0)
      ans += '1';
    else {
      if (pos == 1)
        ans += "10";
      else
        ans += "11";
    }
    string str[12] = {"00", "01", "10", "11", "00", "10",
                      "11", "01", "00", "11", "01", "10"};
    while (ans.size() < cnt) {
      ans.insert((pos == 0 ? 1 : 2), str[pos * 4 + t % 4]);
      t /= 4;
    }
    cout << zhuan(ans) << endl;
  }
  return 0;
}
