#include using namespace std; const long long lim = 1e16; long long tp[100], stp[100]; void init() { long long s = 1; tp[0] = 1; stp[0] = 1; for (int i = 1 ; s <= 1e16 ; i++) { stp[i] = stp[i - 1] * 2 + s + 1; s = s * 2 + 1; tp[i] = s; } } long long query(long long m) { if (m <= 0) return 0; int x = 0; for (x = 0 ; tp[x] <= m ; x++); --x; return stp[x] + query(m - tp[x] - 1) + m - tp[x]; } int main() { init(); int t; long long m; scanf("%d", &t); while(t--) { scanf("%I64d", &m); printf("%I64d\n",query(m)); } return 0; }