#include using namespace std; int main(){ int T; cin >> T; for (int i = 0; i < T; i++){ long long N; cin >> N; N++; vector>> cnt(61, vector>(2, vector(16, 0))); vector>> sum(61, vector>(2, vector(16, 0))); cnt[60][0][0] = 1; for (int j = 59; j >= 0; j--){ for (int k = 0; k < 2; k++){ for (int l = 0; l < 16; l++){ for (int m = 0; m < 2; m++){ if (!(k == 0 && (N >> j & 1) == 0 && m == 1)){ int k2 = k; if ((N >> j & 1) == 1 && m == 0){ k2 = 1; } int l2 = ((l & 7) << 1) | m; if (l == 13 && m == 0){ l2 = 6; } cnt[j][k2][l2] += cnt[j + 1][k][l]; sum[j][k2][l2] += sum[j + 1][k][l]; if (l % 4 != 3 && l != 13 && m == 1){ sum[j][k2][l2] += cnt[j + 1][k][l]; } } } } } } long long ans = 0; for (int j = 0; j < 16; j++){ ans += sum[0][1][j]; } cout << ans << endl; } }