#include <bits/stdc++.h>
using namespace std;
namespace std {}
int main() {
  long long t;
  cin >> t;
  for (long long one = 0; one < t; one++) {
    long long x;
    cin >> x;
    long long conx = x, cmod = (x - 1) % 3;
    long long lb = 0, ans[60] = {0};
    for (long long two = 59; two > -1; two--) {
      long long tp = 1;
      tp = tp << two;
      if (x >= tp) {
        x -= tp;
        lb = max(lb, two);
      }
    }
    if (lb % 2 == 1) {
      --lb;
    }
    long long tp = 1;
    tp = tp << lb;
    conx -= tp;
    conx = (conx / 3);
    conx += tp;
    for (long long two = 59; two > -1; two--) {
      long long tp = 1;
      tp = tp << two;
      if (conx >= tp) {
        conx -= tp;
        ans[two] = 1;
      }
    }
    while (lb >= 0) {
      if (cmod == 1) {
        if (ans[lb + 1] == 1 && ans[lb] == 0) {
          ans[lb] = 1;
        } else if (ans[lb + 1] == 1 && ans[lb] == 1) {
          ans[lb + 1] = 0;
        } else if (ans[lb + 1] == 0 && ans[lb] == 1) {
          ans[lb + 1] = 1;
          ans[lb] = 0;
        }
      } else if (cmod == 2) {
        if (ans[lb + 1] == 1 && ans[lb] == 0) {
          ans[lb + 1] = 0;
          ans[lb] = 1;
        } else if (ans[lb + 1] == 1 && ans[lb] == 1) {
          ans[lb] = 0;
        } else if (ans[lb + 1] == 0 && ans[lb] == 1) {
          ans[lb + 1] = 1;
        }
      }
      lb -= 2;
    }
    long long num = 0;
    for (long long one = 0; one < 59; one++) {
      long long tp = 1;
      if (ans[one] == 1) {
        tp = tp << one;
        num += tp;
      }
    }
    cout << num << endl;
  }
}
