#include <bits/stdc++.h>
using namespace std;
long long r(long long n, long long s[], long long a[], long long su[],
            long long ti[][3]) {
  long long i, max, sum, min, f;
  f = (n - 1) % 3 + 1;
  n = (n - f) / 3;
  for (i = 0; i < 28; i++) {
    if (n < su[i]) {
      break;
    }
  }
  n = n - su[i - 1];
  sum = 0;
  sum += f * s[i - 1];
  for (i = 27; i >= 0; i--) {
    a[i] = n / s[i];
    n -= a[i] * s[i];
  }
  for (i = 0; i < 28; i++) {
    sum += ti[a[i]][f - 1] * s[i];
  }
  return sum;
}
int main() {
  std::ios::sync_with_stdio(false);
  long long t, n, i, h;
  long long s[28];
  long long a[28];
  long long su[28];
  long long ti[4][3];
  ti[0][0] = 0;
  ti[0][1] = 0;
  ti[0][2] = 0;
  ti[1][0] = 1;
  ti[1][1] = 2;
  ti[1][2] = 3;
  ti[2][0] = 2;
  ti[2][1] = 3;
  ti[2][2] = 1;
  ti[3][0] = 3;
  ti[3][1] = 1;
  ti[3][2] = 2;
  cin >> t;
  s[0] = 1;
  su[0] = 0;
  for (i = 1; i < 28; i++) {
    s[i] = s[i - 1] * 4;
    su[i] = su[i - 1] + s[i - 1];
  }
  while (t--) {
    cin >> n;
    cout << r(n, s, a, su, ti) << endl;
  }
  return 0;
}
