#include <bits/stdc++.h>
using namespace std;
bool v[101000];
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long rangei = 1, pow4 = 1, range = 3, st = 0;
    long long mod3 = n % 3;
    long long ans;
    while (n > st + range) {
      st += range;
      pow4 <<= 2;
      ++rangei;
      range = pow4 * 3;
    }
    switch (mod3) {
      case 1:
        ans = 1 * pow4;
        break;
      case 2:
        ans = 2 * pow4;
        break;
      default:
        ans = 3 * pow4;
        break;
    }
    long long ind = ((n - st) - 1) / 3 + 1;
    long long baseans = ind - 1;
    pow4 = 1;
    long long case1ans = baseans, case2ans, case0ans;
    for (int i = 1; i <= rangei - 1; ++i) {
      long long final2 = baseans % 4;
      baseans >>= 2;
      case1ans = final2;
      switch (final2) {
        case 0:
          case2ans = 0;
          case0ans = 0;
          break;
        case 1:
          case2ans = 2;
          case0ans = 3;
          break;
        case 2:
          case2ans = 3;
          case0ans = 1;
          break;
        case 3:
          case2ans = 1;
          case0ans = 2;
          break;
      }
      switch (mod3) {
        case 1:
          ans += case1ans * pow4;
          break;
        case 2:
          ans += case2ans * pow4;
          break;
        default:
          ans += case0ans * pow4;
          break;
      }
      pow4 <<= 2;
    }
    cout << ans << endl;
  }
}
