import sys input = sys.stdin.readline sys.setrecursionlimit(10**7) from functools import lru_cache import pypyjit pypyjit.set_param('max_unroll_recursion=-1') two = [1] * 65 for i in range(64): two[i + 1] = two[i] * 2 @lru_cache(maxsize=None) def f(n): if n <= 0: return 0 now = 0 for i in range(1, 65): if two[i] - 1 > n: break now = two[i] - 1 r = n - now return f(now // 2) * 2 + (now + 1) // 2 + f(r - 1) + r T = int(input()) for _ in range(T): N = int(input()) print(f(N))