## https://yukicoder.me/problems/no/2938 def solve(N): array = [] while N > 0: array.append(N % 2) N //= 2 array.reverse() answer = 0 p = 0 for i in range(len(array)): n = len(array) - 1 - i if n > 0: if array[i] == 1: a = n * pow(2, n - 1) b = pow(2, n) answer += a + p * b else: answer += p if array[i] == 1: answer += p + 1 p += array[i] return answer def main(): T = int(input()) answers = [] for _ in range(T): N = int(input()) ans = solve(N) answers.append(ans) for ans in answers: print(ans) if __name__ == "__main__": main()