#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  unsigned long long int pre[28];
  pre[0] = 1;
  for (__typeof(28) i = (1) - ((1) > (28)); i != (28) - ((1) > (28));
       i += 1 - 2 * ((1) > (28))) {
    pre[i] = 4 * pre[i - 1];
  }
  for (__typeof(28) i = (0) - ((0) > (28)); i != (28) - ((0) > (28));
       i += 1 - 2 * ((0) > (28))) {
    pre[i] *= 3;
  }
  for (__typeof(28) i = (1) - ((1) > (28)); i != (28) - ((1) > (28));
       i += 1 - 2 * ((1) > (28))) {
    pre[i] += pre[i - 1];
  }
  long long int l = 0, r = 27;
  long long int ind = 0;
  while (l <= r) {
    long long int mid = (l + r) / 2;
    if (pre[mid] >= n) {
      ind = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  if (ind >= 1) n -= pre[ind - 1];
  long long int a = 1, b = 2, c = 3;
  long long int x = 0;
  while (x < ind) {
    a <<= 1;
    b <<= 1;
    c <<= 1;
    a <<= 1;
    b <<= 1;
    c <<= 1;
    x++;
  }
  if (n % 3 == 0)
    x = n / 3;
  else
    x = n / 3 + 1;
  x--;
  long long int y = 0, z = 0;
  long long int i = 0;
  while (i <= 63) {
    long long int f = 0, s = 0;
    if (1 & (x >> i)) {
      f = 1;
    }
    if (1 & (x >> (i + 1))) {
      s = 1;
    }
    long long int temp1 = 0, temp2 = 0;
    if (f == 0 && s == 0) {
      i += 2;
      continue;
    } else if (f == 1 && s == 0) {
      temp1 |= (1LL << (i + 1));
      temp2 |= (1LL << i);
      temp2 |= (1LL << (i + 1));
    } else if (f == 0 && s == 1) {
      temp1 |= (1LL << (i));
      temp1 |= (1LL << (i + 1));
      temp2 |= (1LL << i);
    } else {
      temp1 |= (1LL << (i));
      temp2 |= (1LL << (i + 1));
    }
    y |= temp1;
    z |= temp2;
    i += 2;
  }
  a |= x;
  b |= y;
  c |= z;
  long long int k = (n + 2) % 3;
  if (k == 0)
    cout << a << endl;
  else if (k == 1)
    cout << b << endl;
  else
    cout << c << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
