#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second < b.second)
    return true;
  else if (a.second == b.second)
    return a.first < b.first;
  else
    return false;
}
bool sortbyboth(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first < b.first)
    return true;
  else if (a.first == b.first)
    return a.second < b.second;
  else
    return false;
}
unsigned long long powr(unsigned long long x1, unsigned long long n1) {
  if (x1 == 0) {
    return 0;
  }
  unsigned long long result = 1;
  while (n1 > 0) {
    if (n1 & 1) {
      result = (result * x1);
    }
    n1 = n1 >> 1;
    x1 = (x1 * x1);
  }
  return result;
}
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long modinv(long long n, long long p) { return power(n, p - 2, p); }
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  int t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    if (n <= 3) {
      cout << n << endl;
      continue;
    }
    long long cur = 2;
    long long sum = pow(2, cur) - 1;
    long long l = 1;
    while (sum < n) {
      cur += 2;
      sum = pow(2, cur) - 1;
      l++;
    }
    long long m = n;
    m -= (pow(2, cur - 2) - 1);
    string s1 = "", s2 = "", s3 = "";
    s1 = "01";
    s2 = "10";
    s3 = "11";
    cur -= 2;
    while (m > 0 && cur > 0) {
      long long r1 = (pow(2, cur) - pow(2, cur - 2));
      long long r = m / r1;
      if (m % r1) r++;
      if (r == 1) {
        s1 += "00";
        s2 += "00";
        s3 += "00";
      } else if (r == 2) {
        s1 += "01";
        s2 += "10";
        s3 += "11";
      } else if (r == 3) {
        s1 += "10";
        s2 += "11";
        s3 += "01";
      } else {
        s1 += "11";
        s2 += "01";
        s3 += "10";
      }
      m -= r1 * (r - 1);
      cur -= 2;
    }
    long long one = 1;
    if (n % 3 == 1) {
      long long ans = 0;
      reverse(s1.begin(), s1.end());
      for (int i = 0; i < s1.size(); i++) {
        if (s1[i] == '1') {
          ans += (one << i);
        }
      }
      cout << ans << endl;
    } else if (n % 3 == 2) {
      long long ans = 0;
      reverse(s2.begin(), s2.end());
      for (int i = 0; i < s2.size(); i++) {
        if (s2[i] == '1') {
          ans += (one << i);
        }
      }
      cout << ans << endl;
    } else if (n % 3 == 0) {
      long long ans = 0;
      reverse(s3.begin(), s3.end());
      for (int i = 0; i < s3.size(); i++) {
        if (s3[i] == '1') {
          ans += (one << i);
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
