#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  long long int n;
  vector<long long int> res;
  for (int run = 0; run < t; run++) {
    cin >> n;
    bool turn = 1;
    res.push_back(0);
    while (n != 0) {
      if (n % 2 == 0 && (n / 2 % 2 == 1 || n / 2 == 2)) {
        if (turn) {
          res[run] += n / 2;
        }
        n = n / 2;
        turn = !turn;
      } else {
        if (turn) {
          res[run]++;
        }
        n -= 1;
        turn = !turn;
      }
    }
  }
  for (int i = 0; i < t; i++) {
    cout << res[i] << endl;
  }
  cin.sync();
  cin.get();
  return 0;
}
