#include <bits/stdc++.h>
using namespace std;
int get_a(int order) {
  switch (order) {
    case 0:
      return 0;
    case 1:
      return 1;
    case 2:
      return 2;
    case 3:
      return 3;
  }
}
int get_b(int order) {
  switch (order) {
    case 0:
      return 0;
    case 1:
      return 2;
    case 2:
      return 3;
    case 3:
      return 1;
  }
}
int get_c(int order) {
  switch (order) {
    case 0:
      return 0;
    case 1:
      return 3;
    case 2:
      return 1;
    case 3:
      return 2;
  }
}
int get(int type, int order) {
  switch (type) {
    case 0:
      return get_c(order);
    case 1:
      return get_a(order);
    case 2:
      return get_b(order);
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    unsigned long long n;
    cin >> n;
    int type = n % 3;
    unsigned long long tmp = 1;
    while (tmp * 4 <= n) {
      tmp *= 4;
    }
    n -= tmp;
    n /= 3;
    unsigned long long ans = 0;
    int x = 0;
    while (n > 0) {
      ans += get(type, n % 4) * pow(4, x++);
      n /= 4;
    }
    switch (type) {
      case 0:
        ans += 3 * tmp;
        break;
      case 1:
        ans += tmp;
        break;
      case 2:
        ans += 2 * tmp;
        break;
    }
    cout << ans << endl;
  }
}
