The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills.

The boy is now looking at the ratings of consecutive participants written in a binary system. He thinks that the more such ratings differ, the more unfair is that such people are next to each other. He defines the difference between two numbers as the number of bit positions, where one number has zero, and another has one (we suppose that numbers are padded with leading zeros to the same length). For example, the difference of $5 = 101_2$ and $14 = 1110_2$ equals to $3$, since $0101$ and $1110$ differ in $3$ positions. Johnny defines the unfairness of the contest as the sum of such differences counted for neighboring participants.

Johnny has just sent you the rating sequence and wants you to find the unfairness of the competition. You have noticed that you've got a sequence of consecutive integers from $0$ to $n$. That's strange, but the boy stubbornly says that everything is right. So help him and find the desired unfairness for received numbers.


-----Input-----

The input consists of multiple test cases. The first line contains one integer $t$ ($1 \leq t \leq 10\,000$) — the number of test cases. The following $t$ lines contain a description of test cases.

The first and only line in each test case contains a single integer $n$ ($1 \leq n \leq 10^{18})$.


-----Output-----

Output $t$ lines. For each test case, you should output a single line with one integer — the unfairness of the contest if the rating sequence equals to $0$, $1$, ..., $n - 1$, $n$.


-----Example-----
Input
5
5
7
11
1
2000000000000

Output
8
11
19
1
3999999999987



-----Note-----

For $n = 5$ we calculate unfairness of the following sequence (numbers from $0$ to $5$ written in binary with extra leading zeroes, so they all have the same length):   $000$  $001$  $010$  $011$  $100$  $101$ 

The differences are equal to $1$, $2$, $1$, $3$, $1$ respectively, so unfairness is equal to $1 + 2 + 1 + 3 + 1 = 8$.

Source: codeforces | Difficulty: MEDIUM
Tags: Bit manipulation

Mathematics

Greedy algorithms


Solutions:
def f(n):
	return 2 ** (n + 1) - 2 - n

def check(p, n, i):
	if n == p // 2 + 1:
		return f(i - 1) + i
	if n < p // 2 + 1:
		return check((p - 1) // 2, n, i - 1)
	else:
		return f(i - 1) + i + check((p - 1) // 2, n - p // 2 - 1, i - 1)
for _ in range(int(input())):
	n = int(input())
	i = 1
	p = 1
	while p < n:
		p = p * 2 + 1
		i += 1
	print(check(p, n, i))


t = int(input())
for i in range(t):
	n = int(input())
	ans2 = 0
	num2 = 1
	while num2 <= n:
		ans2 += n // num2
		num2 *= 2
	print(ans2)


t = 1
t = int(input())
for _ in range(t):
	n = int(input()) + 1
	ans = 0
	k = 0
	for i in range(len(bin(n)[2:])):
		factor = 2 ** k
		ans += n // factor - 1
		k += 1
		if n % factor != 0:
			ans += 1
	print(ans)


d = {}
d[0] = 1
for i in range(1, 61):
	d[i] = d[i - 1] * 2
for i in range(int(input())):
	n = int(input())
	ans = n
	count = 1
	while d[count] <= n:
		ans += n // 2 ** count
		count += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = '{0:b}'.format(n)
	setBits = s.count('1')
	print(2 * n - setBits)


from math import log2
from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	c = 0
	for j in range(int(log2(n)) + 2):
		c += n // (1 << j)
	stdout.write(str(c) + '\n')


import math
for _ in range(int(input())):
	n = int(input())
	l = []
	sum = 0
	while n > 0:
		sum += n
		n //= 2
	print(sum)


t = int(input())
while t:
	t = t - 1
	n = int(input())
	b = bin(n).replace('0b', '').count('1')
	print(2 * n - b)


import sys
input = sys.stdin.readline
from math import ceil, floor, factorial

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(10000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	n = int(input())
	ans = 0
	k = 1
	while n:
		if n & 1:
			half = n // 2 + 1
		else:
			half = n // 2
		ans += half * k
		k += 1
		n -= half
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	out = 0
	power = 1
	while power <= n:
		out += n // power
		power *= 2
	print(out)


from collections import deque
from collections import OrderedDict
import math
import sys
import os
from io import BytesIO
import threading
import bisect
import heapq
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
input = lambda : sys.stdin.readline().rstrip('\r\n')
ara = [0] * 100005
listOdd = list()

def aratosfen():
	global ara
	for i in range(2, int(math.sqrt(len(ara)))):
		if ara[i] == 0:
			for j in range(i * 2, len(ara), i):
				ara[j] = 1
	global listOdd
	for i in range(2, len(ara)):
		if ara[i] == 0:
			listOdd.append(i)

def run(str1, met, omet, f, l, s):
	fl = False
	cOp = 0
	for i in range(f, l, s):
		if str1[i] == met:
			fl = True
		elif fl == True and str1[i] == omet:
			cOp += 1
	return cOp

def bit(v):
	atr1 = []
	while v > 0:
		if v % 2 == 1:
			atr1.append(1)
		else:
			atr1.append(0)
		v = v // 2
	return atr1
pCal = [1] * 70
dp = [0] * 70
for i in range(len(pCal) - 1, -1, -1):
	cal = 0
	cal += i + (i + 1)
	step = 2
	for j in range(i - 1, 0, -1):
		cal += j * step
		step *= 2
	dp[i] = cal
for t in range(int(input())):
	n = int(input())
	ar1 = bit(n)
	answer = 0
	for i in range(len(ar1) - 1, -1, -1):
		if ar1[i] == 1:
			answer += dp[i]
	print(answer)


t = int(input())
for t in range(t):
	n = int(input())
	n = bin(n)
	binary = n[len(n) - 1:1:-1]
	ans = 0
	for x in range(len(binary)):
		if binary[x] == '1':
			ans += 2 ** (x + 1) - 1
	print(ans)


for tc in range(int(input())):
	n = int(input())
	b = bin(n)[2:]
	l = len(b)
	maxi = 2 ** l
	ans = n
	for i in range(1, l):
		ans += n // 2 ** i
	print(ans)


import math
ll = [1]
for i in range(1, 64):
	ll.append(ll[-1] * 2)

def f(n):
	ans = 0
	while n > 0:
		k = 0
		for i in range(63, -1, -1):
			if n & ll[i] > 0:
				k = i
				break
		ans += ll[k + 1] - 1
		n -= ll[k]
	return ans
for _ in range(int(input())):
	n = int(input())
	print(f(n))


for _ in range(int(input())):
	n = int(input())
	l = len(bin(n)) - 2
	smallest = 2 ** (l - 1)
	ans = 0
	for i in range(l):
		ans += n // 2 ** i
	print(ans)


import math
T = int(input())
for _ in range(T):
	n = int(input())
	ans = 2 * n - sum([c == '1' for c in '{:0b}'.format(n)])
	print(ans)


for i in range(int(input())):
	num = int(input())
	s = 0
	f = 0
	temp = num
	while temp > 0:
		s += num // 2 ** f
		f += 1
		temp //= 2
	print(s)


for _ in range(int(input())):
	n = int(input())
	print(2 * n - bin(n)[2:].count('1'))


import math, sys, bisect
from collections import defaultdict, Counter, deque

def input():
	return sys.stdin.readline().strip()
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])
for _ in range(int(input())):
	N = int(input())
	print(2 * N - bin(N).count('1'))


import sys
import math as mt
input = sys.stdin.buffer.readline
t = int(input())
for __ in range(t):
	n = int(input())
	fr = n // 4
	suma = fr * 7
	fr = fr * 4 + 1
	l = [0, 1, 2, 1, 3]
	for i in range(fr, n + 1):
		x = i % 4
		suma += l[x]
	i = 3
	while 2 ** i <= n:
		suma += n // 2 ** i
		i += 1
	print(suma)


for _ in range(int(input())):
	n = int(input())
	val = 0
	ans = n
	result = 0
	while ans > 0:
		val += 1
		ans //= 2
	for i in range(val + 1):
		result += n // 2 ** i
	print(result)


t = int(input())
for k in range(t):
	n = int(input())
	ans = 0
	while n > 0:
		ans += n
		n >>= 1
	print(ans)


from collections import defaultdict as dd

def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))

def ar(element, size):
	return [element for i in range(size)]

def digitsum(num):
	su = 0
	while num:
		su += num % 10
		num //= 10
	return su

def yes():
	print('YES')

def no():
	print('NO')

def countDivisibles(A, B, M):
	if A % M == 0:
		return B // M - A // M + 1
	return B // M - A // M
from math import floor
Testcase = inin()
for _ in range(Testcase):
	x = inin()
	a = 1
	cnt = 0
	while a <= x:
		cnt += countDivisibles(a, x, a)
		a *= 2
	print(cnt)


t = int(input(''))
num = []
for i in range(t):
	num.append(int(input('')))
for i in num:
	sol = 0
	while i > 0:
		sol += i
		i = i // 2
	print(sol)


for _ in range(int(input())):
	n = int(input())
	ind = 0
	ans = 0
	while n // 2 ** ind:
		ans += n // 2 ** ind
		ind += 1
	print(ans)


from collections import Counter as C, defaultdict as D, deque as Q
from operator import itemgetter as I
from itertools import product as P
from bisect import bisect_left as BL, bisect_right as BR
from heapq import heappush as HPUSH, heappop as HPOP
from math import floor as MF, ceil as MC, gcd as MG, factorial as F, sqrt as SQRT, inf as INFINITY, log as LOG

def player1():
	print('')

def player2():
	print('')

def isPrime(n):
	for i in range(2, MC(SQRT(n)) + 1):
		if n % i == 0:
			return False
	return True

def main():
	for _ in range(int(input())):
		n = int(input())
		ans = 0
		i = 0
		while n:
			if n // pow(2, i) == 0:
				break
			ans += n // pow(2, i)
			i += 1
		print(ans)
main()


t = int(input())
for tc in range(t):
	n = int(input())
	x = 1
	y = 2
	it = 1
	cnt = 0
	while (n + x) // y:
		cnt += (n + x) // y * it
		x *= 2
		y *= 2
		it += 1
	print(cnt)


from math import *
from io import BytesIO, IOBase
import sys
import os
inf = float('inf')
sys.setrecursionlimit(1 << 10)

def Iint():
	return int(input())

def bin_(num, length=-1):
	s = bin(num)[2:]
	if length == -1:
		return s
	return s.zfill(length)

def main():
	t = Iint()
	for _ in range(t):
		n = Iint()
		a = 2 * n - bin_(2 * n).count('1')
		print(a)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


def calc(l, r, s, q, n):
	if l > n:
		return 0
	if r <= n:
		return s
	m = (l + r) // 2
	res = 0
	if m <= n:
		res += q
	res += calc(l, m - 1, (s - q) // 2, q - 1, n)
	res += calc(m + 1, r, (s - q) // 2, q - 1, n)
	return res

def main():
	t = int(input())
	for i in range(t):
		n = int(input()) - 1
		q = 0
		s = 0
		sz = 0
		while q < 65:
			s = s + s + q + 1
			q += 1
			sz = sz + sz + 1
		res = calc(0, sz - 1, s, q, n)
		print(res)
main()


import sys
input = sys.stdin.buffer.readline
t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	d = 1
	r = 0
	while d <= n:
		r += n // d
		d *= 2
	ans.append(r)
print('\n'.join(map(str, ans)))


for _ in range(int(input())):
	n = int(input())
	one = 0
	for i in bin(n)[2:]:
		if i == '1':
			one += 1
	print(2 * n - one)


from math import log2
for _ in range(int(input())):
	n = int(input())
	c = 0
	for j in range(int(log2(n)) + 2):
		d = n // (1 << j)
		c += int(d)
	print(c)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def fun(n):
	if n == 1:
		return 1
	return n + fun(n // 2)

def foo():
	n = inp()
	ans = fun(n)
	print(ans)
t = inp()
for i in range(t):
	foo()


import sys

def input():
	return sys.stdin.readline().rstrip()
t = int(input())
answers = []
for _ in range(t):
	n = int(input())
	n = n + 1
	divide_by = 1
	ans = 0
	for i in range(100):
		if divide_by > n:
			break
		if n % divide_by == 0:
			ans += n // divide_by - 1
		else:
			ans += n // divide_by
		divide_by = 2 * divide_by
	answers.append(ans)
print(*answers, sep='\n')


t = int(input())
for test in range(0, t):
	n = int(input())
	result = 0
	while n > 0:
		result += n
		n = n // 2
	print(result)


from sys import stdin
input = stdin.readline
a = [1]
for x in range(65):
	a.append(a[-1] * 2)
for _ in range(int(input())):
	n = int(input())
	cnt = 0
	for x in a:
		cnt += n // x
	print(cnt)


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
from math import *
import copy
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def bo(i):
	return ord(i) - ord('a')
from copy import *
from bisect import *
t = fi()
while t > 0:
	t -= 1
	n = fi()
	c = 0
	p = 1
	while p <= n:
		c += n // p
		p *= 2
	print(c)


import sys

def main():
	for t in range(int(input())):
		n = int(input())
		s = bin(n)[2:]
		print(2 * n - s.count('1'))
main()


t = int(input())
for _ in range(t):
	n = int(input())
	largestX = 1
	while 2 ** (largestX + 1) <= n:
		largestX += 1
	cumulativeMultiples = 0
	res = 0
	for x in range(largestX, -1, -1):
		cnt = n // 2 ** x
		res += (cnt - cumulativeMultiples) * (x + 1)
		cumulativeMultiples += cnt - cumulativeMultiples
	print(res)


for _ in range(int(input())):
	x = int(input())
	print(x * 2 - bin(x).count('1'))


def read_list():
	return list(map(int, input().split(' ')))

def print_list(l):
	print(' '.join(map(str, l)))
d = [0]
for i in range(1, 61):
	d.append(d[-1] + (1 << i) - 1)
N = int(input())
for _ in range(N):
	n = int(input())
	ans = 0
	k = 0
	while n:
		if n & 1:
			ans += d[k] + k + 1
		k += 1
		n >>= 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = [0] * 62
	arr[1] = 1
	for i in range(2, 62):
		arr[i] = i + sum(arr[:i])
	x = list('{:b}'.format(n))
	x = [int(p) for p in x]
	x = x[::-1]
	x = [0] + x
	ans = 0
	for (i, p) in enumerate(x):
		ans += arr[i] * p
	print(ans)


ans = []
for kek in range(int(input())):
	n = int(input())
	delta = 0
	for i in bin(n)[2:]:
		if i == '1':
			delta += 1
	ans.append(2 * n - delta)
print(*ans, sep='\n')


from math import ceil
m = {}
i = 1
m[1] = 1
while 2 ** i <= 10 ** 18:
	m[2 ** i] = m[2 ** (i - 1)] * 2 + 1
	i += 1
for _ in range(int(input())):
	n = int(input())
	s = bin(n)[2:]
	p = len(s) - 1
	i = 0
	ans = 0
	while i <= p:
		if s[i] == '1':
			ans += m[2 ** (p - i)]
		i += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	length = 0
	tempn = n
	while tempn > 0:
		length += 1
		tempn = tempn >> 1
	ans = 0
	for i in range(length):
		ans += n // (1 << i)
	print(ans)


import math, bisect
ll = [1]
for i in range(1, 64):
	ll.append(ll[-1] * 2)

def f(n):
	ans = 0
	while n > 0:
		k = bisect.bisect_right(ll, n) - 1
		ans += ll[k + 1] - 1
		n -= ll[k]
	return ans
for _ in range(int(input())):
	n = int(input())
	print(f(n))


for _ in range(int(input())):
	n = int(input())
	total = 0
	while n:
		total += n
		n = n >> 1
	print(total)


from sys import stdin
input = stdin.readline

def main():
	test = int(input())
	for _ in range(test):
		n = int(input())
		c = (n // 2 + n % 2) * 1 + (n // 2 - n // 4) * 2
		e = 0
		d = n // 4
		v = 3
		while d > 2:
			f = d // 2 + d % 2
			e += f * v
			v += 1
			d = d // 2
		e += 1 * v + (d - 1) * (v + 1)
		print(max(0, e) + c)
main()


import sys
T = int(input())
for t in range(T):
	N = int(sys.stdin.readline())
	binN = bin(N)[2:][::-1]
	multiplier = 1
	answer = 0
	for bit in binN:
		if bit == '1':
			answer += (1 << multiplier) - 1
		multiplier += 1
	print(answer)


import sys, collections, math
for _ in range(int(input())):
	n = int(input())
	print(2 * n - bin(n).count('1'))


a = int(input())
for i in range(a):
	n = int(input())
	total = 0
	x = len(bin(n)) - 2
	n += 1
	for i in range(x):
		if n % pow(2, i) == 0:
			total += n // pow(2, i) - 1
		else:
			total += n // pow(2, i)
	print(total)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	two = 1
	for i in range(63):
		ans += n // two
		two *= 2
	print(ans)


for t in range(int(input())):
	n = int(input())
	b = n
	ans = 0
	while n > 1:
		x = len(bin(n).replace('0b', '')) - 1
		ans += 2 ** (x + 1) - 1
		n = n - 2 ** x
	if n == 1:
		print(ans + 1)
	else:
		print(ans)


for t in range(int(input())):
	n = int(input())
	total = 0
	i = 1
	while i <= n:
		total += n // i
		i <<= 1
	print(total)


t = int(input())
for i in range(t):
	n = int(input())
	res = 0
	while n:
		res += n
		n = n // 2
	print(res)


import sys

class CJohnnyAndAnotherRatingDrop:

	def solve(self, tc=0):
		for _ in range(int(input())):
			n = int(input())
			ans = 0
			k = 1
			n -= 1
			while 2 ** (k - 1) - 1 <= n:
				ans += k * ((n - (2 ** (k - 1) - 1)) // 2 ** k) + k
				k += 1
			print(ans)
solver = CJohnnyAndAnotherRatingDrop()
input = sys.stdin.readline
solver.solve()


T = int(input())
for _ in range(T):
	n = int(input())
	(ans, i) = (0, 1)
	while n > 0:
		p = n // 2 + n % 2
		ans += p * i
		i += 1
		n -= p
	print(ans)


import sys
import math
from collections import defaultdict, deque
import heapq
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	cur = 1
	add = 1
	ans = 0
	num = 1
	while add <= n:
		st = add
		add = add << 1
		y = 1 + (n - st) // add
		ans += y * num
		num += 1
		cur += add
	print(ans)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip().split()]

def st():
	return str(input().rstrip())[2:-1]

def val():
	return int(input().rstrip())

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(i) for i in st()]
from math import log2
for _ in range(val()):
	n = val()
	highest = int(log2(n))
	currsum = 0
	ans = 0
	currsum = 0
	while highest >= 0:
		currvalue = 2 ** highest
		currnumbers = n // currvalue - currsum
		currsum += currnumbers
		ans += currnumbers * (highest + 1)
		highest -= 1
	print(ans)


def solve(n):
	sum = 0
	digit = 1
	while digit < 1 << 62:
		sum += n // digit
		digit *= 2
	print(sum)
t = int(input())
for _ in range(t):
	n = int(input())
	solve(n)


import sys
import heapq
import random
import collections
import math

def solve(n):
	console('----- solving ------')
	return sum([n // 2 ** i for i in range(0, 60)])

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
	return
for case_num in range(int(input())):
	n = int(input())
	res = solve(n)
	print(res)


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, sys.stdin.readline().split()))

def num():
	return map(int, sys.stdin.readline().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007

def solve():
	t = nu()
	for tt in range(t):
		cc = 0
		n = nu()
		i = 1
		while i <= n:
			cc += n // i
			i *= 2
		print(cc)
solve()


import sys
import math

def solve(n):
	tmp = n
	cnt = 0
	while n > 0:
		cnt += n & 1
		n >>= 1
	return tmp * 2 - cnt
t = int(sys.stdin.readline().strip())
for i in range(t):
	n = int(sys.stdin.readline().strip())
	print(solve(n))


t = int(input())
results = []
for case in range(t):
	n = int(input())
	ans = 2 * n - bin(n).count('1')
	results.append(ans)
for result in results:
	print(result)


import sys
from math import log2
input = sys.stdin.readline
LI = lambda : list(map(int, input().strip().split()))
MI = lambda : map(int, input().strip().split())
SI = lambda : input().strip('\n')
II = lambda : int(input())
for _ in range(II()):
	n = II()
	ans = 0
	k = int(log2(n))
	for i in range(k + 1):
		ans += n // (1 << i)
	if n == 1 << k + 1:
		ans += 1
	print(ans)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def main():
	for _ in range(ii()):
		n = ii()
		d = 2
		ans = n
		while d <= n:
			ans += n // d
			d *= 2
		print(ans)
main()


import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1000000000.0) + 7
from decimal import Decimal

def main():
	for t in range(int(data())):
		n = int(data())
		k = int(math.log2(n))
		a = 2
		ans = 0
		cnt = 1
		while cnt <= k:
			ans += n // a
			a *= 2
			cnt += 1
		ans += n
		out(ans)
main()


for _ in range(int(input())):
	a = int(input())
	b = a // 2
	while b > 0:
		a += b
		b //= 2
	print(a)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import sqrt, ceil, factorial, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from decimal import Decimal
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
dp = dd(int)
dp[0] = 1
for i in range(1, 65):
	dp[i] = dp[i - 1] * 2
for _ in range(int(data())):
	n = int(data())
	answer = 0
	for i in range(1, 65):
		temp = (n - dp[i - 1] + 1) // dp[i]
		if n >= dp[i - 1] - 1 and (n - dp[i - 1] + 1) % dp[i] != 0:
			temp += 1
		answer += max(0, temp * i)
	out(answer)


lst = []
for j in range(62):
	if j == 0:
		lst.append(1)
	else:
		total = 0
		for k in range(j):
			total += lst[k]
		total += j + 1
		lst.append(total)
t = int(input())
for i in range(t):
	n = '{:b}'.format(int(input()))
	n = n[::-1]
	tot = 0
	for p in range(len(n)):
		if n[p] == '1':
			tot += lst[p]
	print(tot)


def fun(k):
	return 2 * k - bin(k).count('1')
for _ in range(int(input())):
	print(fun(int(input())))


for _ in range(int(input())):
	a = int(input())
	print(2 * a - bin(a).count('1'))


import math
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	ans = n + n // 2
	t = 4
	while n >= t:
		ans += n // t
		t *= 2
	print(ans)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
for i in range(n):
	m = inp()
	res = 0
	cnt = 0
	k = 1
	while k < m:
		k *= 2
		cnt += 1
	while m != 0:
		if m - 2 ** cnt >= 0:
			res += 2 ** (cnt + 1) - 1
			m -= 2 ** cnt
		cnt -= 1
	print(res)


mylist = [0] * 61
mylist[1] = 1
mylist[2] = 3
for i in range(3, 61):
	mylist[i] = 2 * mylist[i - 1] + 1
cases = int(input())
for i in range(cases):
	n = int(input())
	ans = 0
	while n > 0:
		ans += n
		n //= 2
	print(ans)


import sys
input = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	c = 1
	ans = 0
	while n // c:
		ans += n // c
		c <<= 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	b = bin(n)
	b = b[2:]
	a = b.count('1')
	ans = 2 * n - a
	print(ans)


import sys
input = sys.stdin.readline
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda : int(input())
ip = lambda : [int(w) for w in input().split()]

def func(n):
	if n == 1:
		return 0
	return n + func(n // 2)
for _ in range(inp()):
	n = inp()
	ans = func(n)
	print(ans + 1)


import sys
max_int = 1000000001
min_int = -max_int
pows = []
for i in range(1, 62):
	pows.append(2 ** i)
t = int(input())
for _t in range(t):
	n = int(sys.stdin.readline())
	ans = 0
	for (number, one) in enumerate(pows, 1):
		if n - one // 2 < 0:
			break
		ans += number * (1 + (n - one // 2) // one)
	print(ans)


import math
for i in range(int(input())):
	n = int(input())
	ans = n
	k = 2
	while n >= k:
		ans += n // k
		k *= 2
	print(ans)


for t in range(int(input())):
	N = int(input())

	def calc(n):
		if n <= 1:
			return n
		else:
			return calc(n // 2) + n
	print(calc(N))


def main():
	n = int(input())
	x = 2 * n
	while n > 0:
		x -= n % 2
		n = n // 2
	return x
t = int(input())
for fd in range(t):
	print(main())


q = int(input())

def p(d):
	if d == 1:
		return 1
	return d + p(d - 1)
d = [1] * 100
for i in range(2, 100):
	d[i] = i + d[i - 1] * 2
for _ in range(q):
	n = int(input())
	if n < 2:
		print(n)
		continue
	s = bin(n)[2:]
	ans = d[len(s) - 1] + len(s)
	for i in range(1, len(s) - 1):
		if s[i] == '0':
			continue
		l = len(s) - i
		ans += l + d[l - 1]
	ans += int(s[-1])
	print(ans)


t = int(input())
for i in range(t):
	binnr = list(bin(int(input())))[2:]
	binnr.reverse()
	cost = 0
	for bit in range(len(binnr)):
		if binnr[bit] == '1':
			cost += 2 ** (bit + 1) - 1
	print(cost)


total = int(input())
result = []
for i in range(total):
	count = 1
	n = int(input())
	m = n
	while m > 2:
		if m % 2 != 0:
			count += 1
		m //= 2
	result.append(2 * n - count)
for t in result:
	print(str(t))


def rating_drop(n):
	if n == 1:
		return 1
	d_sum = 0
	d = {0: 1}
	j = 1
	i = 2
	while i <= n:
		d_sum = 2 * d[j - 1] + 1
		d[j] = d_sum
		j += 1
		i *= 2
	if i > n:
		diff = n - i // 2
		x = diff
		p = -1
		while x != 0:
			r = x % 2
			p += 1
			if r == 1:
				d_sum += d[p]
			x //= 2
	return d_sum
T = int(input())
for i in range(T):
	n = int(input())
	print(rating_drop(n))


test_case = int(input())
while test_case != 0:
	n = int(input())
	res = 0
	while n:
		res += n
		n //= 2
	print(res)
	test_case -= 1


for i in range(int(input())):
	n = int(input())
	print(2 * n - bin(n).count('1'))


import sys
sys.setrecursionlimit(10000)

class Memoize:

	def __init__(self, f):
		self.f = f
		self.memo = {}

	def __call__(self, *args):
		if not args in self.memo:
			self.memo[args] = self.f(*args)
		return self.memo[args]

class Recurse(Exception):

	def __init__(self, *args, **kwargs):
		self.args = args
		self.kwargs = kwargs

def recurse(*args, **kwargs):
	raise Recurse(*args, **kwargs)

def tail_recursive(f):

	def decorated(*args, **kwargs):
		while True:
			try:
				return f(*args, **kwargs)
			except Recurse as r:
				args = r.args
				kwargs = r.kwargs
				continue
	return decorated
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	i = 1
	while i <= n:
		ans += n // i
		i *= 2
	print(ans)


def solve(m):
	a = 0
	k = m
	while k:
		a += k
		k //= 2
	return a
t = int(input())
for case in range(t):
	n = int(input())
	print(solve(n))


test_case = int(input())
my_list = []
for i in range(test_case):
	my_list.append(int(input()))
for x in range(test_case):
	a = bin(my_list[x])
	b = a.count('1')
	print(my_list[x] * 2 - b)


t = int(input())
for w in range(t):
	n = int(input())
	num = bin(n)[2:]
	i = len(num) - 1
	j = 0
	sum1 = 0
	count = 0
	while i >= 0:
		if num[i] == '1':
			count += 2 ** (j + 1)
			sum1 += 1
		j += 1
		i -= 1
	print(count - sum1)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	for i in range(61):
		ans += n // (1 << i)
	print(ans)


for p in range(int(input())):
	n = int(input())
	ans = 0
	while n > 0:
		ans += n
		n = n // 2
	print(ans)


def main():
	n = int(input())
	r = 0
	while n:
		r += n
		n >>= 1
	return r
t = int(input())
for ti in range(t):
	print(main())


def solve(n):
	unfairness = 0
	m = 1
	while m <= n:
		unfairness += n // m
		m <<= 1
	return unfairness
for T in range(int(input())):
	print(solve(int(input())))


xor = [0 for _ in range(61)]
xor[0] = 1
for i in range(1, 61):
	xor[i] = xor[i - 1] * 2 + 1
for _ in range(int(input())):
	n = int(input())
	bi = bin(n)[2:]
	bi = bi[::-1]
	n = len(bi)
	summ = 0
	for j in range(1, n + 1):
		if bi[j - 1] == '1':
			summ += xor[j - 1]
	print(summ)


t = int(input())
for i in range(0, t):
	n = int(input())
	one = 0
	temp = str(bin(n)[2:])
	for i in range(len(temp)):
		if temp[i] == '1':
			one += 1
	print(n * 2 - one)


import sys
for _ in range(int(sys.stdin.readline().rstrip())):
	n = int(sys.stdin.readline().rstrip())
	t = '{0:b}'.format(n)
	re = 0
	tlen = len(t)
	for i in range(tlen):
		if t[i] == '1':
			re += 2 ** (tlen - i) - 1
	print(re)


t = int(input())
for _ in range(t):
	n = int(input())
	s = '{0:b}'.format(n)
	cnt = 0
	for i in s:
		if i == '1':
			cnt = cnt + 1
	print(2 * n - cnt)


t = int(input())

def fun(n):
	a = bin(2 * n)[2:]
	ans = 0
	for i in a:
		if i == '1':
			ans += 1
	print(2 * n - ans)
while t:
	t -= 1
	n = int(input())
	fun(n)


for _ in range(int(input())):
	n = int(input())
	one = 0
	x = str(bin(n)[2:])
	for i in range(len(x)):
		if x[i] == '1':
			one += 1
	print(n * 2 - one)


def f(n):
	return 0 if not min(1, n) else f(n // 2) + n
for _ in range(int(input())):
	print(f(int(input())))


def countSetBits(n):
	if n == 0:
		return 0
	else:
		return 1 + countSetBits(n & n - 1)
for _ in range(int(input())):
	n = int(input())
	print(2 * n - countSetBits(n))


d = dict()
(d[1], d[2], i) = (1, 3, 2)
while i <= 1000000000000000000:
	i *= 2
	d[i] = 2 * i - 1
for t in range(int(input())):
	n = int(input())
	if n in d.keys():
		print(str(d[n]))
		continue
	b = bin(n)[2:][::-1]
	(ans, i) = (0, 1)
	for k in b:
		if k == '1':
			ans += d[i]
		i *= 2
	print(ans)


for _ in range(int(input())):
	n = int(input())
	c = 0
	x = 1
	while x <= n:
		c += n // x
		x *= 2
	print(c)


t = int(input())
for i in range(t):
	num = int(input())
	bin_str = ''
	res = 0
	while num != 0:
		if num % 2 == 1:
			bin_str = '1' + bin_str
		else:
			bin_str = '0' + bin_str
		num = num // 2
	len_bin_str = len(bin_str)
	for (idx, val) in enumerate(bin_str):
		if val == '1':
			res += 2 ** (len_bin_str - idx) - 1
	print(res)


import sys
input = sys.stdin.readline
t = int(input())
for t1 in range(t):
	n = int(input())
	n1 = bin(n)[2:]
	ans = n
	ans = ans * 2
	for i in range(len(n1)):
		if n1[i] == '1':
			ans -= 1
	print(ans)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys

def solve(n):
	ans = 0
	p = 1
	while p <= n:
		ans += n // p
		p *= 2
	return ans

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		ans = solve(n)
		sys.stdout.write(str(ans) + '\n')
main()


import sys
from math import log
input = sys.stdin.readline
MOD = 10 ** 9 + 7
for t in range(int(input())):
	n = int(input())
	u = int(log(n, 2)) + 1
	au = [0]
	fu = [1]
	for i in range(1, u + 1):
		au.append(i + 2 * au[i - 1])
		fu.append(i + 2 * au[i - 1] + i + 1)
	ans = 0
	for (i, b) in enumerate(bin(n)[2:][::-1]):
		if b == '1':
			ans += fu[i]
	print(ans)


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	res = 0
	n = int(input()) + 1
	for i in range(60, -1, -1):
		tmp = 2 ** i
		if tmp > n:
			continue
		x = n // tmp
		if n % tmp != 0:
			x += 1
		res += x - 1
	print(res)


import math

def check(a):
	count = 0
	i = 1
	while i <= a:
		count = count + a // i
		i *= 2
	return count
for _ in range(int(input())):
	a = int(input())
	print(check(a))


def checker(n):
	ans = 0
	for bit in range(64 - 1, -1, -1):
		if n & 1 << bit:
			ans += (1 << bit + 1) - 1
	return ans
for _ in range(int(input())):
	n = int(input())
	print(str(checker(n)))


from sys import stdin, stdout
import math
from collections import Counter, deque
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
IN = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()
mod = 1000000007

def s(a):
	print(' '.join(list(map(str, a))))

def solve():
	n = I()
	count = 0
	while n > 0:
		count += n
		n //= 2
	print(count)
for i in range(I()):
	solve()


import sys
import os
import heapq
import math
try:
	path = './file/input.txt'
	if os.path.exists(path):
		sys.stdin = open(path, 'r')
except:
	pass
t = int(input())

def printd(value):
	pass

def case():
	n = int(input())
	bit = 1
	result = 0
	while n > 0:
		if n & 1 == 1:
			result += 2 ** bit - 1
		bit += 1
		n = n >> 1
	print(result)
for _ in range(t):
	case()


t = int(input())
for _ in range(t):
	n = int(input())
	odds = (n + 1) // 2
	evens = n // 2
	ans = odds
	m = evens
	mul = 2
	while m > 0:
		next_m = m // 2
		ans += (m - next_m) * mul
		mul += 1
		m = next_m
	print(ans)


for _ in range(int(input())):
	n = int(input())
	ans = 0
	i = 0
	a = []
	while 2 ** i <= n:
		ans += 2 ** i
		a.append(ans)
		i += 1
	rem = n - 2 ** (i - 1)
	while rem > 0:
		j = i
		while 2 ** j > rem:
			j -= 1
		ans += a[j]
		rem -= 2 ** j
		i = j
	print(ans)


def f(n):
	i = 0
	score = 0
	while 2 ** i <= n:
		score += n // 2 ** i
		i += 1
	return score
t = int(input())
for i in range(t):
	print(f(int(input())))


import bisect
di = dict()
i = 1
while i <= 10 ** 18:
	di[i] = i * 2 - 1
	i *= 2
t = int(input())
for _ in range(t):
	n = int(input())
	l = len(bin(n)[2:])
	mi = 2 ** (l - 1)
	ans = 0
	while n > 0:
		if n >= mi:
			ans += di[mi]
			n -= mi
		mi //= 2
	print(ans)


import sys
import math
from sys import stdin, stdout

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def main():
	for t in range(int(input())):
		n = int(input())
		s = bin(n)
		print(2 * n - s.count('1'))
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from functools import lru_cache
lru_cache(maxsize=1000)

def dp(n):
	return 2 * n - bin(n).count('1')
t = int(input())
for _ in range(t):
	print(dp(int(input())))


import math
for _ in range(int(input())):
	n = int(input())
	d = {0: 1}
	x = math.log(n, 2)
	x = int(x)
	cnt = 1
	i = 0
	while i <= x:
		i = i + 1
		cnt = cnt + 2 ** i
		d[i] = cnt
	b = bin(n)
	b = b[2:]
	som = 0
	l = list(b)
	l = l[::-1]
	i = 0
	while i < len(l):
		if l[i] == '1':
			som = som + d[i]
		i = i + 1
	print(som)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for t in range(l()[0]):
	n = l()[0]
	if n == 1:
		print(1)
		continue
	x = len(bin(n)) - 2
	ans = 0
	for i in range(x):
		ans += n // 2 ** i
	print(ans)


import os
import sys
import math
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def dijkstra(start, distance, path, n):
	visited = [False for _ in range(n)]
	distance[start] = 0
	for i in range(n):
		v = -1
		for j in range(n):
			if not visited[v] and (v == -1 or distance[j] < distance[v]):
				v = j
		if distance[v] == math.inf:
			break
		visited[v] = True
		for edge in adj[v]:
			destination = edge[0]
			weight = edge[1]
			if distance[v] + weight < distance[destination]:
				distance[destination] = distance[v] + weight
				path[destination] = v

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def seive(n):
	primes = [True] * (n + 1)
	ans = []
	for i in range(2, n):
		if not primes[i]:
			continue
		j = 2 * i
		while j <= n:
			primes[j] = False
			j += i
	for p in range(2, n + 1):
		if primes[p]:
			ans += [p]
	return ans

def factors(n):
	factors = []
	x = 1
	while x * x <= n:
		if n % x == 0:
			if n // x == x:
				factors.append(x)
			else:
				factors.append(x)
				factors.append(n // x)
		x += 1
	return factors

def main():
	try:
		for _ in range(inp()):
			n = inp()
			print(2 * n - bin(n).count('1'))
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	cnt = 0
	while n != 0:
		cnt += n
		n = n // 2
	print(cnt)


def _sum2(n):
	return 2 * n - bin(n).count('1')
t = int(input())
for i in range(t):
	n = int(input())
	print(_sum2(n))


import math

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b / gcd(a, b)

def bs(arr, l, r, x):
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return arr[mid]
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def swap(list, pos1, pos2):
	(list[pos1], list[pos2]) = (list[pos2], list[pos1])
	return list
power = []
for i in range(64):
	power.append(pow(2, i))
t = int(input())
for _ in range(t):
	n = int(input())
	a = 0
	i = 0
	while 1:
		y = (n - power[i]) // power[i + 1] + 1
		if n - power[i] < 0:
			break
		else:
			a += y * (i + 1)
		i += 1
	print(a)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	while n > 0:
		ans += n
		n = n // 2
	print(ans)


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = [1]
	su = [1]
	co = 2
	while len(arr) != 60:
		arr.append(co + su[-1])
		su.append(arr[-1] + su[-1])
		co += 1
	x = bin(n)[2:]
	y = len(x)
	ans = 0
	for j in range(len(x)):
		if x[j] == '1':
			if len(x) - j - 2 >= 0:
				ans += su[len(x) - j - 2] + len(x) - j
			else:
				ans += len(x) - j
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	n += 1
	res = 0
	for i in range(60, -1, -1):
		temp = 1 << i
		if temp <= n:
			temp1 = n // temp
			if n % temp != 0:
				temp1 += 1
			res += temp1 - 1
	print(res)


def solve():
	n = int(input())
	count = 0
	while n > 1:
		count += n
		n = n // 2
	else:
		print(count + 1)
t = int(input())
for i in range(t):
	solve()


t = int(input())
count = 0
while count < t:
	count += 1
	a = int(input())
	ans = 0
	add = 1
	while a > 0:
		thing = 0
		if a % 2 == 0:
			thing += int(a // 2)
		else:
			thing += int((a + 1) // 2)
		ans += thing * add
		a -= thing
		add += 1
	print(int(ans))


def solve(a):
	t = a
	while a != 1:
		a //= 2
		t += a
	return t
n = int(input())
for i in range(n):
	k = int(input())
	print(solve(k))


dp = [0] * 61
for i in range(1, 61):
	dp[i] = dp[i - 1]
	for j in range(0, i - 1):
		dp[i] += dp[j]
	dp[i] += i
t = int(input())
for i in range(t):
	n = int(input())
	cnt = 1
	ans = 0
	while n:
		if n % 2:
			ans += dp[cnt]
		n = n // 2
		cnt += 1
	print(ans)


from sys import stdin, stdout
import bisect
L = [(0, 0)]
for x in range(1, 61):
	L.append((2 ** x - 1, 2 * L[x - 1][1] + x))
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	(ans, k) = (0, n)
	while k:
		i = bisect.bisect_right(L, (k, float('inf')))
		(m, x) = L[i - 1]
		k -= m
		ans += x
		if k > 0:
			k -= 1
			ans += i
	print(ans)


def solve():
	n = int(input())
	N = bin(n)[2:]
	N = N[::-1]
	Len = len(N)
	(ans, pre_2, pre_1) = (0, 0, 0)
	for i in range(0, Len):
		pre_1 += i + 1
		pre_2 = 2 * pre_2 + i
		if N[i] == '1':
			ans += pre_2 + (i + 1)
	return ans
t = int(input())
for i in range(t):
	ans = solve()
	print(ans)
i + 1


for _ in range(int(input())):
	n = int(input())
	b = bin(n)
	b = b[2:]
	l = len(b)
	x = []
	for i in range(0, l):
		k = n // 2
		if n & 1:
			k += 1
		x.append(k)
		n = n // 2
	s = 0
	for i in range(1, l + 1):
		s += x[i - 1] * i
	print(s)


t = int(input())
for j in range(t):
	n = int(input())
	i = 60
	ans = 0
	pre = 0
	while i > 0:
		x = n // 2 ** i
		ans = ans + (x - pre) * (i + 1)
		pre = x
		i = i - 1
	if n % 2 == 1:
		n = n + 1
	ans = ans + n // 2
	print(ans)


def main():
	t = int(input())
	powers_of_2 = [2 ** x for x in range(59, -1, -1)]
	for _ in range(t):
		n = int(input())
		total = 0
		numqs = 0
		for (idx, power) in enumerate(powers_of_2):
			q = n // power
			real_qs = q - numqs
			numqs += real_qs
			total += real_qs * (60 - idx)
		print(total)
main()


for t in range(int(input())):
	n = int(input())
	ans = n
	while n > 0:
		n = n // 2
		ans += n
	print(ans)


rr = lambda : input().strip()
rri = lambda : int(rr())
rrm = lambda : [int(x) for x in rr().split()]
from sys import stdin, stdout

def sol():
	n = rri()
	res = n
	i = 2
	while i <= n:
		res += n // i
		i *= 2
	print(res)
	return
T = rri()
for t in range(1, T + 1):
	ans = sol()


def read_int():
	n = int(input())
	return n

def read_ints():
	ints = [int(x) for x in input().split(' ')]
	return ints

def solve(n):
	bn = bin(n).count('1')
	return n * 2 - bn
t = read_int()
for case in range(t):
	n = read_int()
	sol = solve(n)
	print(sol)


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	k = bin(n)
	k = k[2:]
	k = list(k)
	k.reverse()
	s = 0
	for i in range(len(k)):
		if k[i] == '1':
			a = 2 ** (i + 1)
			a = a - 1
			s = s + a
	print(s)


t = int(input())
for you in range(t):
	n = int(input())
	ans = 0
	currdiff = 2
	currfirst = 1
	itr = 1
	while 1:
		l = (n - currfirst) // currdiff + 1
		if l == 0:
			break
		ans += l * itr
		currfirst *= 2
		currdiff *= 2
		itr += 1
	print(ans)


from math import floor
INF = 99 ** 9
for _ in range(int(input())):
	n = int(input())
	res = 0
	for i in range(INF):
		ek = i + 1
		t = 2 ** ek
		bas = 2 ** i
		if bas <= n:
			kk = (n - bas) // t
			res = res + ek + kk * ek
		else:
			break
	print(res)


import math
import os
import random
import re
import sys
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	ans = 0
	num_of_ones = 0
	p = 2
	while n > 0:
		a = n & 1
		if a:
			num_of_ones += 1
			ans += p
		p *= 2
		n = n >> 1
	print(ans - num_of_ones)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	n = ii1()
	binn = bin(n)[2:]
	cur = 4
	res = [1, 3]
	for i in range(2, len(binn) + 1):
		res.append(i + 1 + cur)
		cur = res[-1] + cur
		if int('1' + '0' * i, 2) >= n:
			break
	ans = 0
	binn = binn[::-1]
	for i in range(0, len(binn)):
		if binn[i] == '1':
			ans += res[i]
	print(ans)


def N():
	return int(input())

def NM():
	return map(int, input().split())

def L():
	return list(NM())

def LN(n):
	return [N() for i in range(n)]

def LL(n):
	return [L() for i in range(n)]
t = N()
dp = [1]
for i in range(1, 65):
	dp.append(dp[-1] * 2 + 1)

def f():
	n = N()
	ans = 0
	for i in range(65):
		if n % 2 == 1:
			ans += dp[i]
		n //= 2
	print(ans)
for i in range(t):
	f()


def answer(n):
	res = 0
	count = 1
	i = 0
	while True:
		if count << i > n:
			break
		if n & count << i:
			res += 2 ** (i + 1) - 1
		i += 1
	return res
t = int(input())
for i in range(t):
	n = int(input())
	print(answer(n))


def solve(N):
	piv = 1
	ans = 0
	while N:
		red = N // 2 + N % 2
		ans += piv * red
		N -= red
		piv += 1
	return ans
t = int(input())
for i in range(t):
	N = int(input())
	print(solve(N))


for t in range(int(input())):
	n = int(input())
	print(n * 2 - bin(n).count('1'))


t = int(input())
for i in range(t):
	n = int(input())
	count = 0
	div = 1
	while div <= n:
		count += n // div
		div *= 2
	print(count)


def l2(n):
	c = 1
	ans = n
	while c < n:
		c = c * 2
		ans += n // c
	return ans
t = int(input())
while t:
	t -= 1
	n = int(input())
	print(l2(n))


for _ in range(int(input())):
	n = int(input())
	c = 0
	while n != 0:
		a = bin(n)[2:]
		c += 2 ** len(a) - 1
		if len(a) == 1:
			n = 0
		else:
			n = int(a[1:], 2)
	print(c)


def fiasco(n):
	r = bit(n)
	result = 0
	for i in range(len(r)):
		if r[i] == 1:
			result += 2 ** (len(r) - i) - 1
	return result

def bit(n):
	s = []
	while n != 0 and n != 1:
		s.append(n % 2)
		n = n // 2
	s.append(n)
	s.reverse()
	return s
for i in range(int(input().strip())):
	n = input().strip()
	print(fiasco(int(n)))


def check(n):
	t = n
	num_of_set_bits = 0
	while t:
		if t & 1:
			num_of_set_bits += 1
		t = t >> 1
	return 2 * n - num_of_set_bits
t = int(input())
while t:
	n = int(input())
	print(check(n))
	t -= 1


l = []
l.append(0)
for i in range(60):
	l.append(l[-1] + 2 ** i)
for _ in range(int(input())):
	n = int(input())
	ans = 0
	x = bin(n)[2:]
	x = x[::-1]
	for i in range(len(x)):
		if x[i] == '1':
			ans += l[i + 1]
	print(ans)


import os
import sys
from io import BytesIO, IOBase

def solution(n):
	if n == 1:
		write(1)
		return
	binary = bin(n)[2:][::-1]
	res = 0
	for (l, b) in enumerate(binary):
		if b == '0':
			continue
		else:
			temp = l + 1
			last = 2 ** l // 2
			(i, cur) = (1, l)
			while i <= last:
				temp += cur * i
				i *= 2
				cur -= 1
			res += temp
	write(res)

def main():
	for _ in range(r_int()):
		n = r_int()
		solution(n)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


d = [1]
p = 1
z = 10 ** 19
while p < z:
	p *= 2
	d.append(p)
k = len(d)
for _ in range(int(input())):
	n = int(input())
	ans = 0
	for i in range(k):
		if n >= d[i]:
			ans += n // d[i]
		else:
			break
	print(ans)


import math
import itertools
t = int(input())
for _ in range(t):
	n = int(input())
	ans = int(0 * math.e)
	while n > 0:
		ans += n
		n >>= 1
	print(ans)


from math import log
for _ in range(int(input())):
	n = int(input())
	d = n
	ans = 0
	for i in range(61):
		c = 2 ** i
		if n & c != 0:
			ans += 2 ** (i + 1) - 1
	print(ans)


def main():
	n = int(input())
	ans = 0
	while n:
		ans += n
		n = n // 2
	print(ans)
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


t = int(input())
for _ in range(0, t):
	n = int(input())
	x = len(bin(n)[2:])
	ans = 0
	for i in range(x):
		ans = ans + n // 2 ** i
	print(ans)


for _ in range(int(input())):
	n = int(input())
	res = 0
	for j in range(64):
		res += n // (1 << j)
	print(res)


for _ in range(int(input())):
	N = int(input())
	ans = 0
	while N:
		ans += N
		N = N // 2
	print(ans)


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	p = 1
	a = 0
	while n // p > 0:
		a = a + n // p
		p = p * 2
	print(a)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	L = n.bit_length()
	k = 1
	for i in range(L):
		ans += n // k
		k *= 2
	print(ans)


def solve():
	n = int(input())
	ans = 0
	for i in range(60):
		if n & 1 << i != 0:
			ans += (1 << i + 1) - 1
	print(ans)
for _ in range(int(input())):
	solve()


import sys
import string
import math
import bisect as bi
input = sys.stdin.readline

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
dp1 = [1] * 100
dp1[0] = 2
for i in range(1, 100):
	dp1[i] = dp1[i - 1] * 2
for i in range(inin()):
	n = inin()
	if n == 1:
		print(1)
	else:
		po = bi.bisect(dp1, n)
		x = dp1[po - 1]
		prev = 0
		ans = 0
		while x > 0:
			ans += (n // x - prev) * (bi.bisect(dp1, x) + 1)
			prev = n // x
			x = x // 2
		print(ans)


t = int(input())
for i in range(t):
	(n, k, s) = (int(input()), 1, 0)
	while n > 0:
		(n, k, s) = (n // 2, k + 1, s + (n + 1) // 2 * k)
	print(s)


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	n = int(input())
	s = n
	while n:
		n //= 2
		s += n
	print(s)


for _ in range(int(input())):
	n = int(input())
	s = 0
	while n:
		s += n
		n //= 2
	print(s)


for i in range(int(input())):
	n1 = int(input())
	bit = 0
	n = n1
	l = []
	while n > 0:
		l.append(n % 2)
		n = n // 2
		bit += 1
	ans = 0
	b = 0
	for i in range(bit):
		if l[i] == 1:
			b += 1
			ans += 2 ** (i + 1)
	print(ans - b)


from sys import stdin, stdout
import math

def main():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(stdin.readline())
		x = 1
		cnt = 0
		while x <= n:
			x *= 2
		x = int(x / 2)
		while n > 0:
			if n - x >= 0:
				cnt += x * 2 - 1
				n -= x
			x = int(x / 2)
		stdout.write(str(cnt) + '\n')
main()


z = int(input())
for h in range(z):
	n = int(input())
	a = n
	mx = 1
	cnt = 0
	while a != 1:
		a = a // 2
		mx += 1
	if n % 2 == 0 and n != 1:
		cnt += n // 2
	else:
		cnt += n // 2 + 1
	x = 2
	y = 4
	for i in range(2, mx + 1):
		if i == 1:
			continue
		else:
			cnt = cnt + ((n - x) // y + 1) * i
			x = x * 2
			y = y * 2
	print(cnt)


import math as m
t = int(input())
for _ in range(t):
	n = int(input())
	s = 0
	i = 1
	while 1 > 0:
		a = (n + 2 ** (i - 1)) // 2 ** i * i
		if a == 0:
			break
		else:
			s += a
			i += 1
	print(s)


for i in range(int(input())):
	n = int(input())
	c = 0
	for i in range(64):
		if n >> i & 1 != 0 >> i & 1:
			c = c + 1
	print(2 * n - c)


from sys import stdin, stdout
from math import log2, floor
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	ans = 0
	for i in range(1, 2 + floor(log2(n))):
		ans += i * (n // (1 << i) + (1 & n >> i - 1))
	stdout.write(str(ans) + '\n')


from math import log2
from sys import stdin
z = ''
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	c = n
	for j in range(1, int(log2(n)) + 2):
		c += n // (1 << j)
	z += str(c) + '\n'
print(z)


show_flg = False
show_flg = True
ans = 0
for _ in range(int(input())):
	ans = 0
	x = int(input())
	s = '00' + bin(x - 1)[2:]
	n = len(s)
	x = int(s, 2)
	y = int(s, 2)
	for i in range(n - 1):
		y >>= 1
		T = y << i + 1
		T += (1 << i) - 1
		tmp = (i + 1) * (y + 1)
		if T > x:
			tmp -= i + 1
		ans += tmp
	print(ans)


import collections
t = int(input())
for i in range(t):
	n = int(input())
	b = bin(n)
	new_b = str(b[2:])
	dp = [0 for i in range(len(new_b))]
	dp[0] = 1
	for j in range(1, len(dp)):
		dp[j] = dp[j - 1] + 2 ** j
	ans = 0
	for j in range(len(dp)):
		if new_b[j] == '1':
			ans += dp[-j - 1]
	print(ans)


def solve():
	n = int(input())
	ans = 0
	for i in range(n.bit_length() + 1):
		if n & 1 << i:
			ans += (1 << i + 1) - 1
	print(ans)
T = int(input())
while T > 0:
	T -= 1
	solve()


t = int(input())
while t:
	n = int(input())
	print(2 * n - bin(n).count('1'))
	t -= 1


for t in range(int(input())):
	n = int(input())
	s = 1
	ans = 0
	cnt = 64
	while cnt >= 0:
		p = (n + 1) // s
		if (n + 1) % s:
			p += 1
		ans += p - 1
		s *= 2
		cnt -= 1
	print(ans)


from sys import stdin
import math
t = int(stdin.readline())
lookup = [1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, 2147483647, 4294967295, 8589934591, 17179869183, 34359738367, 68719476735, 137438953471, 274877906943, 549755813887, 1099511627775, 2199023255551, 4398046511103, 8796093022207, 17592186044415, 35184372088831, 70368744177663, 140737488355327, 281474976710655, 562949953421311, 1125899906842623, 2251799813685247, 4503599627370495, 9007199254740991, 18014398509481983, 36028797018963967, 72057594037927935, 144115188075855871, 288230376151711743, 576460752303423487, 1152921504606846975, 2305843009213693951, 4611686018427387903, 9223372036854775807, 18446744073709551615, 36893488147419103231, 73786976294838206463, 147573952589676412927, 295147905179352825855, 590295810358705651711]
for _ in range(t):
	n = int(stdin.readline())
	answer = 0
	while n > 0:
		exp = 0
		i = 1
		while i << 1 <= n:
			i = i << 1
			exp += 1
		answer += lookup[exp]
		n = n - i
	print(answer)


t = int(input())
for case in range(t):
	n = int(input())
	count = n
	while n > 1:
		n = n // 2
		count += n
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	t = bin(n)[2:]
	sum = 2 * n
	for i in t:
		if i == '1':
			sum -= 1
	print(sum)


from math import floor, log2
dp = [0] * 100

def precompute():
	dp[1] = 1
	for i in range(2, 100):
		dp[i] = (dp[i - 1] << 1) + i

def get_val(i):
	return dp[i] + i + 1

def main():
	n = int(input())
	ans = 0
	for i in range(0, floor(log2(n)) + 1):
		if n & 1 << i:
			ans = ans + get_val(i)
	print(ans)
precompute()
tt = int(input())
for _ in range(tt):
	main()


for _ in range(int(input())):
	n = int(input())
	ans = 0
	m = 1
	i = 1
	while m <= n:
		ans += i * ((n + m) // (2 * m))
		i += 1
		m *= 2
	print(ans)


import sys
import math

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def printspx(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')

def printchk(*args):
	return print(*args, end=' \\ ')
MODPRIME = int(1000000000.0 + 7)
BABYMODPR = 998244353
for _testcases_ in range(int(input())):
	n = int(input())
	(ans, nxt) = (0, 1)
	while nxt <= n:
		ans += n // nxt
		nxt *= 2
	print(ans)


y = [0] * 100
y[0] = 1
for i in range(1, 100):
	y[i] = y[i - 1] * 2 + 1
for i in range(int(input())):
	n = int(input())
	ans = 0
	r = 0
	while n > 0:
		if n % 2 == 1:
			ans = ans + y[r]
		n = n // 2
		r += 1
	print(ans)


for t in range(int(input())):
	n = int(input()) + 1
	result = 0
	i = 1
	while n > 1:
		x = n // 2
		result += x * i
		n -= x
		i += 1
	print(result)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	n += 1
	ans = 0
	digits = math.ceil(math.log(n, 2))
	for i in range(digits):
		ans += n // 2 ** i
		if n % 2 ** i == 0:
			ans -= 1
	print(ans)


def solve(n):
	if n == 1:
		return 1
	return solve(n // 2) + n
t = int(input())
for _ in range(t):
	n = int(input())
	print(solve(n))


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n,) = I()
	an = 1
	for i in range(60):
		x = n >> i + 1
		y = n % 2 ** (i + 1)
		an += x * 2 + (1 if y > 2 ** i else 0)
	print(an)


def val(n):
	res = 0
	val = 1
	while n:
		if n & 1:
			res += val
		n >>= 1
		val = (val + 1) * 2 - 1
	return res
t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	print(val(n))


t = int(input())
for i in range(t):
	number = int(input())
	count_of_iter = len(bin(number)) - 2
	ans = 0
	for j in range(0, count_of_iter):
		ans += (j + 1) * ((number + 2 ** j) // 2 ** (j + 1))
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	ones = 0
	ans = 2 * n
	while n:
		if n & 1:
			ones += 1
		n //= 2
	print(ans - ones)


t = int(input())
for _ in range(t):
	n = int(input())
	s = bin(n)[2:]
	count = 0
	for i in s:
		if i == '1':
			count += 1
	print(2 * n - count)


t = int(input())
while t:
	t -= 1
	n = int(input())
	i = 1
	ans = 0
	while i <= n:
		ans += n // i
		i = i * 2
	print(ans)


def solve():
	x = int(input())
	res = 0
	p = 0
	while x > 0:
		if x % 2 == 1:
			res += (1 << p + 1) - 1
		p += 1
		x //= 2
	print(res)
for n in range(int(input())):
	solve()


def proB(n):
	ans = 0
	for i in range(60):
		ans += n // (1 << i)
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	print(proB(n))


def count_bits(n):
	count = 0
	while n:
		n = n & n - 1
		count += 1
	return count

def f(n):
	return 2 * n - count_bits(n)
t = int(input())
for _ in range(t):
	print(f(int(input())))


from math import log2, floor, ceil
for _ in range(int(input())):
	n = int(input())
	r = bin(n).count('1')
	ans = 2 * n - r
	print(ans)


from sys import *

def solve(x):
	s = x
	i = 2
	while x > 0:
		x = x // i
		s += x
	return s
test = 1
test = int(input())
for t in range(0, test):
	n = int(input())
	ans = solve(n)
	print(ans)


for _ in range(int(input())):
	x = int(input())
	ans = 0
	ref = 1
	while 1:
		if ref == x:
			ans += 1
		elif ref > x:
			break
		else:
			ans += x // ref
		ref *= 2
	print(ans)


for _ in range(0, int(input())):
	n = int(input())
	cnt = 0
	y = str(bin(n)[2:])
	for i in range(len(y)):
		if y[i] == '1':
			cnt += 1
	print(n * 2 - cnt)


from sys import stdin, stdout
from collections import Counter, defaultdict
import math

def readInt():
	return int(stdin.readline())

def readString():
	return stdin.readline()[:-1]

def readListInt():
	return list(map(int, stdin.readline().split()))

def readListStr():
	return list(map(str, stdin.readline().split()))

def nextLine():
	stdout.write('\n')

def show(x):
	stdout.write(str(x) + '\n')

def showInline(x):
	stdout.write(str(x))

def showList(x):
	for i in x:
		stdout.write(str(i) + ' ')
	nextLine()

def show2D(x):
	for i in range(len(x)):
		for j in range(len(x[0])):
			stdout.write(str(x[i][j]) + ' ')
		nextLine()

def emptyList(length, value=-1):
	return [value] * length

def empty2D(row, col, val=-1):
	return [[val for i in range(col)] for j in range(row)]

def isSquare(x):
	if x ** 0.5 * 10 % 10 == 0:
		return 1
	return 0

def isLog(val, base):
	a = math.log(val, base)
	if a * 10 % 10 == 0:
		return 1
	else:
		return 0

def solve():
	for testcases in range(readInt()):
		n = readInt()
		binary = bin(n)
		binary = binary[2:]
		total = 0
		for i in range(len(binary)):
			total += n
			n //= 2
		show(total)
solve()


def fun(n):
	b = bin(n)[2:]
	l = len(b)
	L = []
	for i in range(l):
		L.append(b[i])
	co = L.count('1')
	num = 2 * int(b, 2) - co
	return num
t = int(input())
for i in range(t):
	n = int(input())
	print(fun(n))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	bn = bin(n).replace('0b', '')
	ans = n * 2
	t = 0
	for i in bn:
		if i == '1':
			t += 1
	print(ans - t)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]

def fun(a, b):
	a = a ^ b
	c = 0
	while a > 0:
		a = a & a - 1
	return c
for _ in range(Int()):
	n = Int()
	bits = len(bin(n)) - 2
	ans = 0
	for i in range(0, bits + 1):
		ans += n // 2 ** i
	print(ans)


def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		denom = 1
		ans = 0
		while denom <= N:
			ans += N // denom
			denom *= 2
		print(ans)
main()


t = int(input())
f = [0] * 70
f[0] = 0
for i in range(1, 70):
	f[i] = f[i - 1] * 2 + i
for _ in range(t):
	n = int(input())
	sum = 0
	for i in range(64, 0, -1):
		if 1 << i <= n < 1 << i + 1:
			sum += f[i] + i + 1
			n -= 1 << i
	if n:
		sum += 1
	print(sum)


t = int(input())
for i in range(t):
	n = int(input())
	p = bin(n)[2:]
	k = len(p)
	j = 0
	s = 0
	while j < len(p):
		if p[j] == '1':
			s += 2 ** k - 1
		k += -1
		j += 1
	print(s)


t = int(input())
for T in range(t):
	x = int(input())
	val = 2 * x
	ans = val
	ans -= bin(val).count('1')
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	d = bin(n).count('1')
	print(2 * n - d)


import sys
input = sys.stdin.readline

def main():
	t = int(input())

	def f(k):
		pw = 2
		s = 0
		while True:
			s += k // pw * (pw // 2)
			s += max(0, k % pw - pw // 2)
			if k < pw:
				break
			pw *= 2
		return s
	for _ in range(t):
		n = int(input())
		s = 0
		pw = 2
		ans = 0
		for t in range(1, 62):
			if n - 1 - s < 0:
				break
			k = (n - 1 - s) // pw
			ans += t * (k + 1)
			s = s * 2 + 1
			pw *= 2
		print(ans)
main()


import math
t = int(input())
for qq in range(t):
	n = int(input())
	step = 2
	s = 0
	val = 1
	while n >= step // 2:
		k = n - step // 2
		s += val
		s += val * (k // step)
		step *= 2
		val += 1
	print(s)


ans = []
for _ in range(int(input())):
	n = int(input())
	ansi = 0
	k = 1
	while k <= n:
		ansi += n // k
		k *= 2
	ans.append(ansi)
print('\n'.join(map(str, ans)))


def f(n):
	count = n
	k = 1
	m = 2
	while n >= m:
		count += n // m
		k += 1
		m *= 2
	return count
numberofcases = int(input())
for _ in range(numberofcases):
	print(f(int(input())))


import sys
import math
import collections
from collections import deque
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
T = 1
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	l = bin(n).replace('0b', '')
	print(2 * n - l.count('1'))


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
for i in range(ip()):
	n = ip()
	x = bin(n).count('1')
	print(2 * n - x)


from math import log2, floor, log, ceil
Power = []
for i in range(61):
	Power.append(2 ** i)

def index(N):
	l = 0
	r = 60
	while l < r:
		mid = l + r >> 1
		if Power[mid] > N:
			r = mid
		else:
			l = mid + 1
	return Power[l - 1]
for _ in range(int(input())):
	N = int(input())
	Val = N
	while N != 0:
		X = index(N)
		Val += X - 1
		N -= X
	print(Val)


def main():
	import sys
	sys.setrecursionlimit(10 ** 6)
	input = sys.stdin.readline
	T = int(input())
	for t in range(T):
		n = int(input())
		p = 1
		ans = 0
		while p <= n:
			ans += n // p
			p *= 2
		print(ans)
main()


from sys import stdin, stdout
T = int(stdin.readline().strip())
from math import log2

def sol(n):
	if n == 0:
		return 0
	if n == 1:
		return 1
	if n % 2 != 0:
		return 1 + sol(n - 1)
	x = 2 ** int(log2(n))
	if x > n:
		x = x // 2
	return x * 2 - 1 + sol(n - x)
for caso in range(T):
	n = int(stdin.readline().strip())
	stdout.write('%d\n' % sol(n))


from bisect import *
(power, res, i) = ([1], [1], 1)
while power[-1] < 10 ** 18:
	power.append(1 << i)
	res.append(2 * power[-1] - 1)
	i += 1
for j in range(int(input())):
	n = int(input())
	ans = 0
	while n > 0:
		index = bisect_right(power, n) - 1
		ans += res[index]
		n -= power[index]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	shit = 0
	k = 1
	while n // k != 0:
		shit += n // k
		k *= 2
	print(shit)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
testcases = int(input())
for j in range(testcases):
	n = int(input())
	binop = bin(n)[2:]
	ans = 0
	for s in range(len(binop)):
		if binop[s] == '1':
			val = len(binop) - s - 1
			cv = 0
			init = 0
			while cv <= val:
				init *= 2
				init += cv
				cv += 1
			ans += init + val + 1
	print(ans)


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n):
	return solve(n // 2) + n if n > 0 else 0
for i in tests():
	n = int_in()
	out(solve(n))


def main():
	for q in range(int(input())):
		n = int(input())
		cnt = 0
		now = 1
		while now <= n:
			cnt += 1
			now *= 2
		ans = 0
		now = 1
		for i in range(cnt):
			ans += (n + now) // (now * 2) * (i + 1)
			now *= 2
		print(ans)
main()


import math
t = int(input())
for q in range(t):
	n = int(input())
	num = math.log(n, 2)
	ans = 0
	for i in range(int(num) + 1):
		ans += n // 2 ** i
	print(ans)


def fun(n):
	if n == 1:
		return 1
	return n + fun(n // 2)
for _ in range(int(input())):
	n = int(input())
	print(fun(n))


for _ in range(int(input())):
	n = int(input())
	b = bin(n)[2:]
	b = list(b)
	sum = n * 2 - b.count('1')
	print(sum)


import math
t = int(input())
for i in range(t):
	n = int(input())
	c = int(math.log(n, 2))
	s = 0
	for j in range(c + 1):
		s += n // 2 ** j
	print(s)


for _ in range(int(input())):
	n = int(input())
	r = bin(n).replace('0b', '').count('1')
	k = 2 * n - r
	print(k)


t = int(input())
while t > 0:
	a = int(input())
	s = a
	while a > 0:
		s += a // 2
		a //= 2
	print(s)
	t -= 1


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inar():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		n = int(input())
		c = bin(n).count('1')
		num = n * 2
		print(num - c)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
while t:
	t = t - 1
	n = int(input())
	cnt = 0
	while n != 1:
		cnt += n
		n //= 2
	print(cnt + 1)


import sys
lines = []
for line in sys.stdin:
	if 'Exit' == line.rstrip():
		break
	lines.append(line)
t = int(lines[0])
cumsum = [0]
hi = 0
for j in range(1, t + 1):
	n = int(lines[j])
	s = '{0:064b}'.format(n)
	counter = s.count('1')
	print(n * 2 - counter)


dp = [1]
for i in range(66):
	x = dp[i] * 2 + 1
	dp.append(x)
t = int(input())
for _ in range(t):
	n = int(input())
	n = str(bin(n)[2:])[::-1]
	j = 0
	ans = 0
	for i in n:
		if i == '1':
			ans += dp[j]
		j += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	temp = bin(n)[2:]
	t = len(temp)
	su = 0
	for j in range(t):
		su += n // 2 ** j
	print(su)


exec(int(input()) * "n=int(input())\nprint(2*n-bin(n)[2:].count('1'))\n")


import math
for t in range(int(input())):
	n = int(input())
	N = int(math.log(n, 2)) + 1
	m = 0.5 * N * N + 0.5 * N - 1
	print(int(sum([n // 2 ** i for i in range(int(N))])))


try:
	for _ in range(int(input())):
		n = int(input())
		caa = bin(n).replace('0b', '')
		caa = caa.count('1')
		print(2 * n - caa)
except:
	pass


n = int(input())
answers = [] * 0
for problems in range(n):
	zzz = input()
	xxx = int(zzz)
	ans = 0
	howmany = 0
	count = 0
	for i in range(64, -1, -1):
		howmany = xxx // 2 ** i
		ans += (i + 1) * (howmany - count)
		count += howmany
	answers.append(count)
for answer in answers:
	print(answer)


for _ in range(int(input())):
	n = int(input())
	n = bin(n)[2:][::-1]
	ans = 0
	for i in range(len(n)):
		if n[i] == '1':
			ans += 2 ** (i + 1) - 1
	print(ans)


import os

def f(n):
	if n == 0:
		return 0
	if n == 1:
		return 1
	i = 0
	while 2 ** i < n:
		i += 1
	i -= 1
	if 2 ** (i + 1) == n:
		return 2 ** (i + 2) - 1
	return 2 ** (i + 1) - 1 + f(n - 2 ** i)
t = int(input())
ans = t * [None]
for i in range(t):
	n = int(input())
	ans[i] = str(f(n))
out = '\n'.join(ans)
out = out.encode(encoding='UTF-8')
os.write(1, out)


dp1 = [1]
for i in range(1, 60):
	dp1.append(2 * dp1[-1] + 1)

def func():
	n = int(input())
	n = bin(n)[2:]
	n = n[::-1]
	ans = 0
	for i in range(len(n)):
		if n[i] == '1':
			ans += dp1[i]
	print(ans)
for i in range(int(input())):
	func()


import sys, math
d = [0] * 61
d[0] = 1
for i in range(1, 60):
	d[i] = 2 * d[i - 1] + (i + 1)
tc = int(sys.stdin.readline())
for _ in range(tc):
	n = int(sys.stdin.readline())
	ans = 0
	while n > 1:
		x = 0
		while True:
			if pow(2, x + 1) > n:
				break
			else:
				x += 1
		ans += d[x - 1] + x + 1
		n -= pow(2, x)
	if n:
		print(ans + 1)
	else:
		print(ans)


for _ in range(int(input())):
	n = int(input())
	ans = 0
	for i in range(64):
		ans += n // 2 ** i
	print(ans)


from sys import stdin
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
hg = lambda x, y: (y + x - 1) // x * x
for _ in range(I()):
	n = I()
	sum = n
	i = 1
	while n // 2 ** i != 0:
		sum += n // 2 ** i
		i += 1
	print(sum)


import sys
import math
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
	t -= 1
	n = int(input())
	ans = 0
	i = 0
	while 1 << i <= n:
		ans += i + 1
		i += 1
	y = (n - 1) // 2
	ans += y
	i = 1
	while y > 0:
		y = (n // (1 << i) - 1) // 2
		ans += y * (i + 1)
		i += 1
	print(ans)


def ans(p):
	if p == 1:
		return 1
	return p // 2 + ans(p // 2)
test = int(input())
count = 0
result = 0
while count < test:
	p = int(input())
	count = count + 1
	result = ans(p) + p - 1
	print(result)


def ans(n):
	count = 0
	w = n
	while n >= 1:
		m = n % 2
		n = n // 2
		if m == 1:
			count += 1
	return 2 * w - count
m = int(input())
for i in range(m):
	n = int(input())
	print(ans(n))


import math
count = 0

def solve(n):
	global count
	if n == 0:
		return count
	count = solve(n // 2) + n
	return count
t = int(input())
for _ in range(t):
	count = 0
	n = int(input())
	print(solve(n))


bstr = lambda number: bin(number)[2:]
mismatch = lambda a, b: bstr(a ^ b).count('1')

def solve(n):
	score = 0
	bn = bstr(n)
	l = len(bn)
	for i in range(l):
		if bn[i] == '1':
			score += 2 ** (l - i) - 1
	return score
t = int(input())
for i in range(t):
	n = int(input())
	print(solve(n))


import sys
input = sys.stdin.buffer.readline

def prog():
	for _ in range(int(input())):
		n = int(input())
		ones = 0
		for i in bin(n)[2:]:
			if i == '1':
				ones += 1
		print(2 * n - ones)
prog()


def recur(n):
	if n == 0:
		return 0
	return recur(n // 2) + n
t = int(input())
for hh in range(0, t):
	n = int(input())
	ans = recur(n)
	print(ans)


t = int(input())
answer = []
for t in range(t):
	n = int(input())
	temp = 2 * n - bin(n).count('1')
	answer.append(str(temp))
print('\n'.join(answer))


try:
	for _ in range(int(input())):
		n = int(input())
		s = 0
		while n:
			s += n
			n >>= 1
		print(s)
except EOFError:
	pass


import sys
import math
import collections

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		sys.stdin = fin

def int_split_input():
	return list(map(int, input().split()))
t = int(input())
for ti in range(1, t + 1):
	n = int(input())
	cur = 0
	for i in range(60):
		if n & 1 << i:
			cur += (1 << i + 1) - 1
	print(cur)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mod = 1000000007
import math
import bisect
from decimal import *
getcontext().prec = 50
abc = 'abcdefghijklmnopqrstuvwxyz'

def fn(n):
	c = -1
	while n:
		c += 1
		n //= 2
	return c

def isPowerOfTwo(n):
	if n == 0:
		return False
	while n != 1:
		if n % 2 != 0:
			return False
		n = n // 2
	return True
pi = 3.141592653589793

def main():
	for _ in range(ii()):
		n = ii()
		s = bin(n)
		s = s[2:]
		o = s.count('1')
		ans = 2 * n - o
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import os, sys, atexit
from io import BytesIO, StringIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
t = int(input())
while t:
	t += -1
	n = int(input())
	a = bin(n)[2:]
	cnt = 0
	for i in a:
		if i == '1':
			cnt -= -1
	print(n * 2 - cnt)


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline

def I():
	return list(map(int, inp().split()))
for _ in range(I()[0]):
	(n,) = I()
	b = len(bin(n)[2:])
	ans = 0
	for i in range(b):
		ans += n // 2 ** i
	print(ans)


import math

def func(n):
	if n == 1:
		return 1
	else:
		return n + func(n // 2)
t = int(input())
cnt = 0
for cnt in range(t):
	n = int(input())
	print(func(n))


for _ in range(int(input())):
	n = int(input())
	s = bin(n)[2:]
	s = s[::-1]
	l = len(s)
	sm = 0
	for i in range(l):
		if s[i] == '1':
			sm += pow(2, i + 1) - 1
	print(sm)


def countSetBits(n):
	count = 0
	while n:
		count += n & 1
		n >>= 1
	return count
for _ in range(int(input())):
	n = int(input())
	print(2 * n - countSetBits(n))


import sys
input = sys.stdin.readline
l = [1, 2, 4, 8, 16]
x = 16
while x < 10000000000000000000:
	x = x * 2
	l.append(x)
a = [1, 2, 1, 3, 1, 2, 1]
s = [0] * 7
s[0] = 1
for i in range(1, 7):
	s[i] = s[i - 1] + a[i]
for _ in range(int(input())):
	n = int(input())
	ts = 0
	m = 0
	if n < 8:
		print(s[n - 1])
	else:
		j = -1
		for i in range(0, n):
			if n < l[i]:
				j = i - 1
				break
		if j == -1:
			g = len(l)
			j = g - 1
		prev = 0
		temp = 0
		while l[j] >= 8:
			temp = n // l[j]
			ts += (temp - prev) * (j + 1)
			prev = temp
			j -= 1
		ts += n // 8 * 11
		if n % 8 != 0:
			ts += s[n % 8 - 1]
		print(ts)


import math

def solution():
	n = int(input())
	l = math.ceil(math.log(n, 2)) + 1
	count = 0
	d = 1
	while l > 0:
		count += n // d
		d *= 2
		l -= 1
	print(count)
T = int(input())
for t in range(T):
	solution()


t = int(input())
dp = [0 for i in range(61)]
dp[0] = 0
dp[1] = 1
for i in range(2, 61):
	dp[i] = 2 * dp[i - 1] + i
for _ in range(t):
	n = int(input())
	i = 59
	b = n
	a = [0 for i in range(60)]
	while b > 0:
		a[i] = b % 2
		b >>= 1
		i -= 1
	i = a.index(1)
	ans = 0
	while i < 60:
		if a[i] == 1:
			ans += dp[60 - i - 1] + 60 - i
		i += 1
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	ans = 0
	f = 0
	i = n
	while n:
		ans += i // 2 ** f
		n //= 2
		f += 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
from fractions import Fraction
for _ in range(int(input())):
	nm = int(input())
	a = 0
	i = 1
	raj = 1
	krish = raj
	arnab = 'arn'
	while True:
		res = math.ceil(Fraction(nm - pow(2, i - 1) + 1, pow(2, i)))
		if res <= 0:
			break
		a += res * i
		i += 1
	print(a)


t = int(input())
f = []
f.append(0)
f.append(1)
for i in range(2, 200):
	tmp = 2 * f[i - 1] + 1
	f.append(tmp)
while t > 0:
	t -= 1
	x = int(input())
	b = []
	b.append(0)
	tot = 0
	ans = 0
	while x > 0:
		tmp = x % 2
		x >>= 1
		tot += 1
		b.append(tmp)
	for i in range(1, tot + 1):
		if b[i] > 0:
			ans += f[i]
	print(ans)


import math
t = int(input())
while t:
	i = 0
	result = 0
	n = int(input())
	t = t - 1
	while 2 ** i <= n:
		result += math.floor(n // 2 ** i)
		i = i + 1
	print(result)


def modinv(n, p):
	return pow(n, p - 2, p)
import math

def main():
	for case in range(int(input())):
		n = int(input())
		ans = 0
		rem = n
		p = math.floor(math.log(n, 2))
		k = 2 ** p
		prev = 0
		while rem > 0 and k >= 1:
			temp = n // k
			temp -= prev
			ans += temp * (p + 1)
			rem -= temp
			p -= 1
			prev += temp
			k //= 2
		print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math
t = int(input())
for _ in range(t):
	n = int(input())
	one = (n + 1) // 2
	b = 1
	for i in range(2, int(math.log(n, 2)) + 2):
		b = b * 2
		n1 = n // b
		one += (n1 + 1) // 2 * i
	print(one)


def bitsoncount(x):
	return bin(x).count('1')
t = int(input())
while t:
	n = int(input())
	print(2 * n - bitsoncount(2 * n))
	t -= 1


def read_int():
	return int(input())

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	n = read_int()
	f = dict()
	two = [1]
	f[1] = 1
	i = 1
	while i * 2 <= int(2e+18):
		two.append(i * 2)
		f[i * 2] = f[i] * 2 + 1
		i *= 2
	two.reverse()
	ans = 0
	for t in two:
		if n >= t:
			ans += f[t]
			n -= t
	print(ans)


def solve(n):
	if n == 0:
		return 0
	return n + solve(n // 2)
for _ in range(int(input())):
	print(solve(int(input())))


import math
test = int(input())
for tes in range(test):
	n = int(input())
	mt = int(math.log(n, 2))
	i = 0
	ans = 0
	while i <= mt:
		ans += n // 2 ** i
		i += 1
	print(ans)


T = int(input())
while T:
	n = int(input())
	c = str(bin(n)).count('1')
	print(2 * n - c)
	T = T - 1


def an(n):
	if n == 0:
		return 0
	a = 1 + 3 * (n - 1)
	a += 2 ** (n + 1) - 4 + -4 * (n - 1)
	return a

def answer(n):
	unfairness = 0
	binary = str(bin(n))[2:]
	binary_list = list(reversed([int(i) for i in binary]))
	for i in range(len(binary_list)):
		if binary_list[i] == 1:
			_len = i + 1
			unfairness += an(i) + _len
	return unfairness
testCount = int(input())
for _ in range(testCount):
	n = int(input())
	print(answer(n))


t = int(input())
for i in range(t):
	n = int(input())
	p = 0
	res = 0
	while 1 << p <= n:
		power = 1 << p
		if power & n > 0:
			res += power * 2 - 1
		p += 1
	print(res)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	count = 0
	while n >= 1:
		count += n
		n = n // 2
	print(count)


def main():
	from sys import stdin
	from sys import stdout
	input = stdin.readline
	print = stdout.write
	t = int(input())
	for _ in range(t):
		n = int(input())
		answer = 0
		number = 1
		while number <= n:
			answer += n // number
			number *= 2
		print('{0}\n'.format(answer))
main()


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	n = int(input())

	def f(n):
		if n == 1:
			return 1
		return f(n // 2) + n
	print(f(n))
t = int(input())
for _ in range(t):
	main()


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
for _ in range(int(input())):
	n = int(input())
	b = bin(n)[2:]
	z = pow(2, len(b))
	ans = 0
	for i in b:
		if i == '1':
			ans += z - 1
		z = z // 2
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	ans = 0
	i = 0
	while n >= 2 ** i:
		ans += n // 2 ** i
		i += 1
	print(int(ans))


import sys

def I():
	return sys.stdin.readline().rstrip()
for tc in range(1, 1 + int(I())):
	n = int(I())
	ans = 0
	while n:
		ans += n
		n //= 2
	print(ans)


import math
answers = [1]
x = 1
current = 1
while x <= 10 ** 18:
	x = 2 * x
	current = current * 2 + 1
	answers.append(current)

def unfairness(n, answers):
	ans = 0
	while n:
		log = math.log(n, 2)
		i = int(log)
		if n - 2 ** i >= 0:
			n -= 2 ** i
			ans += answers[i]
		else:
			n -= 2 ** (i - 1)
			ans += answers[i - 1]
	return ans
t = int(input())
a = []
for i in range(t):
	a.append(int(input()))
for x in a:
	print(unfairness(x, answers))


import sys
input = sys.stdin.buffer.readline

def solution():
	a = [1, 2, 1, 3, 1, 2, 1]
	for _ in range(int(input())):
		n = int(input())
		ans = 0
		s = 0
		for i in range(61, -1, -1):
			x = n // 2 ** i
			x -= s
			s += x
			ans += x * (i + 1)
		print(ans)
solution()


d = {1: 1, 2: 3, 3: 4}

def count(n):
	if n == 0:
		return 0
	a = str(bin(n).replace('0b', ''))
	b = len(a)
	if b < 3:
		return d[n]
	ans = 2 ** b
	extra = n - 2 ** (b - 1)
	return ans + count(extra) - 1
for _ in range(int(input())):
	n = int(input())
	print(count(n))


t = int(input())
for _ in range(t):
	n = int(input())
	res = 0
	while n:
		res += n
		n = n >> 1
	print(res)


import os
import sys, math
from io import BytesIO, IOBase

def main():
	t = int(input())
	for i in range(t):
		n = int(input()) + 1
		v = 1
		ans = 0
		for j in range(61):
			if v > n:
				break
			if n % v != 0:
				ans += n // v
			else:
				ans += n // v - 1
			v *= 2
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math as m
for _ in range(int(input())):
	n = int(input())
	ans = n
	while n:
		n = n // 2
		ans += n
	print(ans)


import sys
from collections import defaultdict, deque

def solve():
	n = int(input())
	a = [int(x) for x in bin(n)[2:]]
	n = len(a)
	ans = 0
	for i in range(n):
		l = n - i
		if a[i]:
			ans += (1 << l) - 1
	print(ans)
t = 1
t = int(input())
for case in range(1, t + 1):
	ans = solve()


def dec_to_bin(N):
	if not hasattr(dec_to_bin, 'table'):
		dec_to_bin.table = '01'
	(x, y) = divmod(N, 2)
	return dec_to_bin(x) + dec_to_bin.table[y] if x else dec_to_bin.table[y]
for i in range(int(input())):
	n = int(input())
	ns = dec_to_bin(n)
	ns = ns[::-1]
	s = 0
	for j in range(len(ns)):
		if ns[j] == '1':
			s += 2 ** (j + 1) - 1
	print(s)


from math import ceil, floor, sqrt, log

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def is_prime(n):
	for i in range(2, floor(sqrt(n) + 1)):
		if n % i == 0:
			return False
	return True

def find_k(n):
	for k in range(0, ceil(n / 2) + 1):
		if is_prime(k + n):
			return k

def get_graph(n):
	k = find_k(n)
	m = n + k
	print(m)
	for i in range(1, n):
		print(i, i + 1)
	print(n, 1)
	for i in range(1, k + 1):
		print(i, i + floor(n / 2))

def alice_wins(n, k):
	if n < k:
		if n % 3 != 0:
			return True
		return False
	if alice_wins(k - 1, k):
		if (n - (k + 1)) % 3 != 0:
			return True
	elif (n - (k + 2)) % 3 != 0:
		return True
	return False

def prime_factorization(x):
	answer = []
	i = 2
	while i * i <= x:
		if x % i == 0:
			answer.append(i)
			while x % i == 0:
				x //= i
		i += 1
	if x > 1:
		answer.append(x)
	return answer

def pf(X, N):
	answer = 1
	m = pow(10, 9) + 7
	x_primes = prime_factorization(X)
	for prime in x_primes:
		power = 0
		factor = prime
		while factor <= N:
			power += N // factor
			factor *= prime
		answer *= pow(prime, power, m)
		answer %= m
	return answer

def find_ops(n):
	c = floor(n / 3)
	n -= 3 * floor(n / 3)
	b = floor(n / 2)
	n -= 2 * floor(n / 2)
	return n + b + c

def count_operations(a, b):
	if a < b:
		val = int(log(b / a, 2))
		if pow(2, val) * a == b:
			return find_ops(val)
	else:
		val = int(log(a / b, 2))
		if pow(2, val) * b == a:
			return find_ops(val)
	return -1

def find_m(n, x):
	return 1 + max(0, (n - pow(2, x - 1) + 1) // pow(2, x))

def find_total_diff(n):
	n -= 1
	total = n // 2 + 1
	x = 1
	while pow(2, x) - 1 <= n:
		total += (x + 1) * find_m(n, x + 1)
		x += 1
	return total
t = 1
t = int(input())
while t:
	t = t - 1
	n = int(input())
	print(find_total_diff(n))


from math import log2, ceil
t = int(input())
for __ in range(t):
	n = int(input())
	bit = 1 + int(log2(n))
	ans = 0
	for i in range(bit):
		x = (n + 1) // (1 << i)
		if (n + 1) % (1 << i) == 0:
			ans += x - 1
		else:
			ans += x
	print(ans)


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	n2 = n
	ct = 0
	while n > 0:
		if n & 1 == 1:
			ct += 1
		n = n >> 1
	ans = 2 * n2 - ct
	print(ans)


from math import ceil
import sys
input = sys.stdin.readline
from collections import defaultdict as dd
t = int(input())
while t:
	n = int(input())
	a = 1
	ans = 0
	n += 1
	while a < n:
		x = n // a
		if n % a:
			x += 1
		ans += x - 1
		a = a * 2
	print(ans)
	t -= 1


import sys
from math import log2

def read():
	return sys.stdin.readline().strip()

def write(a):
	sys.stdout.write(a)

def solve(n):
	res = n
	x = 2
	while n >= x:
		res += n // x
		x *= 2
	return res

def bruh():
	t = int(read())
	ans = [0] * t
	for i in range(t):
		n = int(read())
		ans[i] = solve(n)
	write('\n'.join(map(str, ans)))
bruh()


for t in range(int(input())):
	n = int(input())
	su = n // 2 + (n % 2 == 1)
	i = 2
	d = 2
	while i <= n:
		su += (n // i - n // (i * 2)) * d
		d += 1
		i = i * 2
	print(su)


import math
dp = {2 ** i: 2 ** (i + 1) - 1 for i in range(61)}

def solver_for_2k(n):
	return dp[n]

def solve(n):
	ans = 0
	p = 1
	while n > 0:
		if n % 2 == 1:
			ans += solver_for_2k(p)
		n = n // 2
		p *= 2
	return ans

def read():
	t = int(input())
	for i in range(t):
		n = int(input())
		ans = solve(n)
		print(ans)
read()


inputn = int(input())
ans = []
a = []
max = 0
for i in range(inputn):
	c = int(input())
	b = bin(c).replace('0b', '')
	l = len(b)
	a.append(b)
	if max < l:
		max = l
bin = []
b2 = 0
b1 = 1
for i in range(1, max + 1):
	b1 = b2 + i
	bin.append(b1)
	b2 = b2 + b1
for i in a:
	w = 0
	l = len(i)
	for j in range(l):
		if i[l - j - 1] == '1':
			w = w + bin[j]
	ans.append(w)
for i in ans:
	print(i)


def solve(n):
	ans = 0
	count = 0
	i = 1
	while count <= n:
		first_occurence = 2 ** (i - 1)
		deltas = 2 ** i
		if n < first_occurence:
			break
		val = 1 + (n - first_occurence) // deltas
		ans += i * val
		count += val
		i += 1
	return ans
for _ in range(int(input())):
	print(solve(int(input())))


import sys
input = sys.stdin.readline
test = int(input())
while test != 0:
	test -= 1
	n = int(input())
	su = 0
	while n != 0:
		su += n
		n //= 2
	print(su)


import sys
import bisect as b
import math
input = sys.stdin.readline
mo = 10 ** 9 + 7

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def computeGCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
for i in range(inin()):
	n = inin()
	ans = 0
	while n > 0:
		ans += n
		n = n // 2
	print(ans)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():

	def solve():
		n = int(inputi())
		i = 1
		res = 0
		while i <= n:
			if n % (i * 2) >= i:
				res += 2 * i - 1
			i *= 2
		print(res)
	q = int(inputi())
	for _ in range(q):
		solve()
main()


from sys import stdin, stdout
for case in range(int(stdin.readline())):
	n = int(stdin.readline())
	total = 0
	while n:
		total += n
		n = n // 2
	print(total)


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
res = ['Yes', 'No']
pow = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976, 2305843009213693952, 4611686018427387904, 9223372036854775808]
test_case = ii()
while test_case:
	test_case -= 1
	n = ii()
	c = 0
	l = len(pow) - 1
	while n:
		if pow[l] <= n:
			n -= pow[l]
			c += pow[l + 1] - 1
		l -= 1
	print(c)


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
T = int(stdin.readline())
a = [0]
for i in range(1, 60):
	a.append(2 * a[i - 1] + i)
for _ in range(T):
	n = int(stdin.readline())
	if n == 1:
		print(1)
		continue
	b = bin(n)[2:]
	l = len(b)
	ans = 0
	for i in range(l):
		if b[i] == '1':
			j = l - i
			ans = ans + j + a[j - 1]
	print(ans)


import os
import sys
import io
import math
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for t in range(int(input())):
	n = int(input())
	answer = 0
	while n != 0:
		answer += n
		n //= 2
	print(answer)


t = int(input())
for i in range(t):
	n = int(input())
	i = 1
	p = 0
	while i <= n:
		p = p + n // i
		i = 2 * i
	print(p)


from math import ceil
for iota in range(int(input())):
	n = int(input())
	ans = 0
	i = 1
	while n > 0:
		if n % 2 == 0:
			ans += i * (n >> 1)
			n -= n >> 1
			i += 1
			continue
		if n % 2 == 1:
			ans += i * ((n >> 1) + 1)
			n -= (n >> 1) + 1
			i += 1
	print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		r = n
		for i in range(1, 64):
			r += n // (1 << i)
		rr.append(r)
	return JA(rr, '\n')
print(main())


for nt in range(int(input())):
	n = int(input())
	print(2 * n - bin(n).count('1'))


testcases = int(input())
for testcase in range(testcases):
	n = int(input())
	if n == 1:
		print(1)
		continue
	if n == 2:
		print(3)
		continue
	if n == 3:
		print(4)
		continue
	if n == 4:
		print(7)
		continue
	if n == 5:
		print(8)
		continue
	count = 0
	while n >= 1:
		if n == 1:
			count += 1
			break
		count += n
		n = n >> 1
	print(count)


import math
lis = [0] * 61
c = 0
for i in range(61):
	lis[i] = sum(lis[:i]) + c + 1
	c += 1
for _ in range(int(input())):
	n = int(input())
	ans = 0
	a = 2 ** 60
	while n > 0:
		while a > n:
			a = a // 2
		aa = int(math.log(a, 2))
		ans += lis[aa]
		if aa == 0:
			break
		n = n - a
	print(ans)


from decimal import *
import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, floor, log2
from heapq import heappush, heappop, heapify, nlargest, nsmallest

def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def sortListWithIndex(listOfTuples, idx):
	return sorted(listOfTuples, key=lambda x: x[idx])

def sortDictWithVal(passedDic):
	temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
	toret = {}
	for tup in temp:
		toret[tup[0]] = tup[1]
	return toret

def sortDictWithKey(passedDic):
	return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
t = INT()
while t != 0:
	n = INT()
	ans = 0
	for i in range(61):
		if n >> i & 1:
			ans += (1 << i + 1) - 1
	print(ans)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	ans = 0
	x = 1
	while True:
		k = n // x
		if k == 0:
			break
		ans += k
		x *= 2
	print(ans)


t = int(input())
while t >= 1:
	n = int(input())
	s = 1
	cnt = int(0)
	while 1:
		cnt += n // s
		if n // s == 0:
			break
		s = s * 2
	t = t - 1
	print(cnt)


t = int(input())
for _ in range(t):
	x = int(input())
	t = bin(x)[2:]
	result = 2 * x
	for i in t:
		if i == '1':
			result -= 1
	print(result)


t = int(input())
for ab in range(t):
	n = int(input())
	k = n
	count = 1
	l = n
	while n >= 2 ** count:
		l += n // 2 ** count
		count += 1
	print(l)


def func():
	n = int(input())
	ans = 0
	for i in range(0, 62):
		if 1 << i & n == 1 << i:
			ans += (1 << i + 1) - 1
	print(ans)
no = int(input())
for i in range(0, no):
	func()


t = int(input())
while t:
	n = int(input())
	b = bin(n)
	c = b.count('1')
	print(2 * n - c)
	t -= 1


import math
t = int(input())
for i in range(t):
	n = int(input())
	if n == 1:
		print(1)
		continue
	ans = 0
	for j in range(1, 100):
		end = (n + 2 ** (j - 1)) // 2 ** j
		pq = j * end
		ans += pq
	print(ans)


test = int(input())
for _ in range(test):
	a = int(input())
	highestPower = 0
	for i in range(64):
		if 1 << i <= a:
			highestPower = i
		else:
			break
	lst = [0] * (highestPower + 1)
	for i in range(highestPower + 1):
		lst[i] = a // (1 << i)
	for i in range(highestPower):
		lst[i] = lst[i] - lst[i + 1]
	ans = 0
	for i in range(highestPower + 1):
		ans = ans + (1 + i) * lst[i]
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = bin(n)
	a = a[2:]
	l = a.count('1')
	print(2 * n - l)


from math import log2
from sys import stdin
t = int(stdin.readline())
z = [0] * t
for _ in range(t):
	n = int(stdin.readline())
	c = 0
	for j in range(int(log2(n)) + 2):
		c += n // (1 << j)
	z[_] = c
print(*z, sep='\n')


import math
for ad in range(int(input())):
	n = int(input())
	ans = 0
	for i in range(1, int(math.log(n, 2)) + 3):
		ans += i * ((n + 2 ** (i - 1)) // 2 ** i)
	print(ans)


import math
t = int(input())
for i in range(t):
	n = int(input())
	result = n
	p = 1
	while p <= n:
		p = p << 1
		result += n // p
	print(result)


t = int(input())
for _ in range(t):
	n = int(input())
	n = n + 1
	(p, ans) = (1, 0)
	for i in range(70):
		if n % p == 0:
			ans += n // p - 1
		else:
			ans += n // p
		p *= 2
	print(ans)


from sys import stdin
import math

def solve():
	return

def main():
	inp = stdin.readline
	for _ in range(int(inp())):
		n = int(inp())
		x = n
		pos = 0
		i = 1
		while x > 0:
			if x & 1 == 1:
				pos = i
			i += 1
			x >>= 1
		ans = 0
		k = 1
		for i in range(pos):
			ans += n // k
			k <<= 1
		print(ans)
main()


import sys
import math

def I():
	return int(sys.stdin.readline())

def IL():
	return list(map(int, sys.stdin.readline().strip().split()))

def ILS():
	return list(map(str, sys.stdin.readline().strip().split()))
t = I()
fib = [2, 3]
tot = 2 + 3
for i in range(59):
	fib.append(tot)
for iii in range(t):
	n = I()
	ans = n
	x = 2
	while x <= n:
		ans += n // x
		x *= 2
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	n = bin(n).replace('0b', '')
	c = 0
	for (i, x) in enumerate(list(n[::-1])):
		if x == '1':
			c += 2 ** (i + 1) - 1
	print(c)


import math
t = int(input())
dp = {0: 1, 1: 3, 2: 7}

def get_total(num):
	if num in dp:
		return dp[num]
	total = 0
	for i in range(0, num):
		total += get_total(i)
	dp[num] = total + num + 1
	return dp[num]

def get_binary(x):
	return '{0:b}'.format(x)
for i in range(t):
	n = int(input())
	x = get_binary(n)
	x = x[::-1]
	total = 0
	for i in range(len(x)):
		if x[i] == '1':
			total += get_total(i)
	print(total)


import sys
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	w = len(bin(n)) - 2
	a = [0]
	for i in range(1, w + 2):
		a.append(2 * a[i - 1] + 1)
	s = 0
	while n > 0:
		k = len(bin(n)) - 2
		n -= int('1' + '0' * (k - 1), 2)
		s += a[k]
	print(s)


from math import log2, floor, ceil
for _ in range(int(input())):
	n = int(input())
	r = len(bin(n)[2:])
	ans = 0
	for i in range(r):
		ans += n // 2 ** i
	print(ans)


T = int(input())
l = [1]
for iss in range(60):
	l.append(l[-1] * 2 + 1)
for isc in range(T):
	a = int(input())
	s = bin(a)[2:]
	s = s[::-1]
	ret = 0
	for i in range(len(s)):
		ret += int(s[i]) * l[i]
	print(ret)


for _ in range(int(input())):
	number = int(input())
	ans = 0
	while number:
		ans += number
		number //= 2
	print(ans)


t = int(input())

def f(n):
	cnt = 0
	while n:
		cnt += n
		n //= 2
	return cnt
for _ in range(t):
	n = int(input())
	print(f(n))


import queue
import math
t = int(input())
while t:
	n = int(input())
	ans = 0
	x = 1
	while x <= n:
		ans += n // x
		x *= 2
	print(ans)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	j = n
	count = 0
	while j != 0:
		j &= j - 1
		count += 1
	print(n * 2 - count)


import sys
from math import log2, floor, ceil, sqrt
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

def solve(n):
	arr = []
	while n > 0:
		arr.append(n % 2)
		n = n // 2
	return arr
for _ in range(int(ri())):
	n = int(ri())
	arr = solve(n)
	ans = 0
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] == 1:
			ans += 2 ** (i + 1) - 1
	print(ans)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math

def solve_k(k):
	if k == 0:
		return 0
	if k == 1:
		return 1
	return 2 * solve_k(k - 1) + k

def diff_n_n1(n):
	bit_len = n.bit_length()
	s1 = bin(n)[2:].rjust(bit_len, '0')
	s2 = bin(n - 1)[2:].rjust(bit_len, '0')
	return sum([1 for i in range(bit_len) if s1[i] != s2[i]])

def count(n):
	cnt = 0
	for i in range(1, n + 1):
		cnt += diff_n_n1(n)
	return cnt

def solve(n):
	cnt = 0
	while n > 0:
		p = n.bit_length() - 1
		pp = 2 ** p
		cnt += solve_k(p)
		if n >= pp:
			cnt += p + 1
		n -= pp
	return cnt

def main():
	for _ in range(ri()):
		n = ri()
		print(solve(n))
main()


from math import log2

def div(a, b):
	global cnt
	return b // a - cnt
for _ in range(int(input())):
	n = int(input())
	k = int(log2(n))
	ans = 0
	s = 0
	cnt = 0
	while k >= 0:
		ans += k * div(1 << k, n)
		cnt = n // (1 << k)
		k -= 1
	print(ans + n)


import math

def Divisors(n):
	l = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

def SieveOfEratosthenes(n):
	l = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return l

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	result.append(n)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def main():
	n = int(input())
	s = 0
	while n > 0:
		s += n
		n = n // 2
	print(s)
t = int(input())
for i in range(0, t):
	main()


dp = [0]
for i in range(1, 60):
	dp.append(2 * dp[i - 1] + i)
t = int(input())
for _ in range(t):
	n = int(input())
	if n == 1:
		print(1)
		continue
	else:
		b = bin(n)[2:]
		ln = len(b)
		value = 0
		for x in range(ln):
			if b[x] == '1':
				i = ln - x
				value += i + dp[i - 1]
		print(value)


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def solve():
	a = I()
	l = len(bin(a)[2:])
	c = 1
	ans = 0
	for j in range(1, l + 1):
		ans += a // c
		c *= 2
	print(ans)
for _ in range(I()):
	solve()


import sys
from collections import Counter
T = int(input().strip())
for t in range(T):
	n = int(input().strip())
	res = 0
	d = 1
	while n + 1 > d:
		res += (n + 1) // d + (1 if (n + 1) % d else 0) - 1
		d *= 2
	print(res)


ll = lambda : list(map(int, input().split()))
s = lambda : input()
v = lambda : map(int, input().split())
ii = lambda : int(input())
import math
from collections import Counter

def r(a, i):
	ss = a // i
	if a / i >= ss + 0.5:
		ans = math.ceil(a / i)
	else:
		ans = a // i
	return ans
for _ in range(ii()):
	a = ii()
	c = 2
	ans = 0
	t = 1
	while c // 2 <= a:
		ans = ans + t
		ans += t * ((a - c // 2) // c)
		c *= 2
		t += 1
	print(ans)


import math

def r(a, i):
	ss = a // i
	if a / i >= ss + 0.5:
		ans = math.ceil(a / i)
	else:
		ans = a // i
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	c = 2
	s = 0
	t = 1
	while c // 2 <= n:
		s += t
		s += t * ((n - c // 2) // c)
		c *= 2
		t += 1
	print(s)


from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))
for _ in range(I()):
	n = I()
	ans = n * 2
	b = bin(n)
	b = b.count('1')
	print(ans - b)


import math
from sys import stdin
input = stdin.readline

def solve():
	n = int(input())
	if n == 1:
		print(1)
	elif n == 2:
		print(3)
	else:
		c = bin(n)[2:]
		s = len(c)
		sum1 = 0
		for i in range(0, s):
			if c[i] == '1':
				v = s - i
				sum1 += pow(2, v) - 1
		print(sum1)
for _ in range(int(input())):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(bin(n))
	a = a[2:]
	a.reverse()
	cost = 0
	for j in range(len(a)):
		if a[j] == '1':
			cost += 2 ** (j + 1) - 1
	print(cost)


import sys

def input():
	return sys.stdin.readline().rstrip('\r\n')

def List():
	return list(map(int, input().split()))

def Num():
	return int(input())

def solve():
	n = Num()
	return 2 * n - bin(n).count('1')
for _ in range(Num()):
	print(solve())


t = int(input())
while t != 0:
	n = int(input())
	bitPosition = 1
	result = 0
	while n > 0:
		if n & 1 == 1:
			result += 2 ** bitPosition - 1
		bitPosition += 1
		n = n >> 1
	print(result)
	t -= 1


import sys

def solve_query():
	r = 0
	for i in range(150):
		if n // 2 ** i == 0:
			break
		r += n // 2 ** i
	print(r)
lines = sys.stdin.readlines()
t = int(lines[0])
for i in range(1, t + 1):
	n = int(lines[i])
	solve_query()


from math import log

def getAns(n):
	ans = 0
	for i in range(60):
		if n & pow(2, i):
			ans += pow(2, i + 1) - 1
	return ans
for _ in range(int(input())):
	n = int(input())
	print(getAns(n))


for i in range(int(input())):
	n = int(input())

	def code(s):
		if s < 1:
			return 0
		if s == 1:
			return 1
		return s + code(s // 2)
	print(code(n))


import math
I = input
for _ in range(int(I())):
	n = int(I())
	t = math.log(n, 2)
	t = math.ceil(t) if t % 1.0 != 0 else math.ceil(t) + 1
	c = 0
	for i in range(t):
		c += n // 2 ** i
	print(c)


def func(n):
	if n == 1:
		return 0
	return n + func(n // 2)
t = int(input())
for i in range(0, t):
	n = int(input())
	ans = func(n)
	print(ans + 1)


testy = int(input())
results = []
liczby = []
liczby.append(0)
liczby.append(1)
summ = 1
for i in range(2, 61):
	liczby.append(2 * summ + 1)
	summ = liczby[i]
for i in range(testy):
	n = int(input())
	res = 0
	x = bin(n)
	y = x[2:len(x) + 1]
	for j in range(len(y)):
		if y[j] == '1':
			res = res + liczby[len(y) - j]
	results.append(res)
for result in results:
	print(result)


__multitest__ = True

def solve():
	n = int(input())
	ans = 0
	for b in range(0, 64):
		if 1 << b > n:
			break
		else:
			ans += n // (1 << b)
	print(ans)
t = 1 if not __multitest__ else int(input())
for tt in range(t):
	solve()


from sys import stdin
input = lambda : stdin.readline().strip()
char = [chr(i) for i in range(97, 123)]
CHAR = [chr(i) for i in range(65, 91)]
mp = lambda : list(map(int, input().split()))
INT = lambda : int(input())
rn = lambda : range(INT())
mod = 10000000007
from math import ceil, sqrt, factorial, gcd
for _ in rn():
	n = INT()
	k = bin(n)[2:]
	ans = 0
	for i in range(len(k) - 1, -1, -1):
		h = pow(2, len(k) - i)
		ans += max(0, 2 * (n // h) - 1)
		rem = n - h * (n // h)
		if rem == n:
			if k[i] == '1':
				ans += 1
		elif rem < h // 2:
			ans += 1
		else:
			ans += 2
	print(ans)


t = int(input())
while t != 0:
	n = int(input())
	n += 1
	b = bin(n)[2:]
	ans = 0
	i = 0
	while 1:
		p = pow(2, i)
		temp = n
		div = temp // p
		mod = temp % p
		if mod > 0:
			div += 1
		ans += div - 1
		if div - 1 == 0:
			break
		i += 1
	print(ans)
	t -= 1


import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

def n(n):
	return (n ** 2 + n) // 2

def d(n, m):
	ans = 0
	for i in range(max(n, m).bit_length() + 1):
		k = 1 << i
		if n & k != m & k:
			ans += 1
	return ans

def slv(N):
	ans = 0
	for i in range(N.bit_length() + 1):
		if N & 1 << i != 0:
			ans += (1 << i + 1) - 1
	return ans

def main():
	T = read_int()
	for _ in range(T):
		N = read_int()
		print(slv(N))
main()


def findef(n):
	if n == 0:
		return 0
	return findef(n // 2) + n
cases = int(input())
for t in range(cases):
	n = int(input())
	print(findef(n))


for asdf in range(int(input())):
	cur = int(input())
	res = bin(cur)
	cnt = 0
	for i in range(len(res)):
		if res[i:i + 1] == '1':
			cnt += 1
	print(2 * cur - cnt)


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
for _ in range(int(input())):
	n = int(input())
	ans = 0
	for i in range(len(bin(n)) - 2):
		ans += n // 2 ** i
	print(ans)


import math
t = int(input())
for i in range(t):
	n = int(input())
	ls = []
	for j in range(int(math.log2(n)) + 1):
		ls.append((n >> j & 1) * 2 ** j)
	ls.reverse()
	ans = 0
	for j in range(len(ls)):
		ans += max(0, 2 * ls[j] - 1)
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	d = 2
	ans = n
	for i in range(int(math.log(n, 2))):
		if (n + 1) % d == 0:
			ans += (n + 1) // d - 1
		else:
			ans += (n + 1) // d
		d *= 2
	print(ans)


from collections import Counter, defaultdict, deque
from math import *
import sys
input = sys.stdin.readline

def solve():
	a = int(input())
	b = bin(a)[2:]
	n = len(b)
	c = 0
	res = 0
	for d in b:
		if d == '1':
			res += n * (c + 1)
			c *= 2
			c += 1
		else:
			res += n * c
			c *= 2
		n -= 1
	print(res)
tt = int(input())
for test in range(tt):
	solve()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
import math

def gift():
	for _ in range(t):
		n = int(input())
		bina = bin(n)[2:]
		lenn = len(bina)
		ans = 0
		for i in range(lenn):
			if bina[i] == '1':
				ans += 2 ** (lenn - i) - 1
		yield ans
t = int(input())
ans = gift()
print(*ans, sep='\n')


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import heapq
import sys
input = sys.stdin.readline
from bisect import *
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rls = lambda : list(map(str, input().split()))
t = int(input())
for _ in range(0, t):
	n = int(input())
	x = len(bin(n)[2:])
	ans = 0
	for i in range(x):
		ans = ans + n // 2 ** i
	print(ans)


import math
testCases = int(input())
inputs = []
d = {}
for i in range(testCases):
	inputs.append(int(input()))

def initialResult():
	for i in range(math.ceil(math.log2(max(inputs))) + 2):
		d[2 ** i] = 2 ** (i + 1) - 1

def findResult(number):
	a = number
	res = 0
	while a != 1:
		res += a
		a = a // 2
	return res + 1
initialResult()
for i in inputs:
	print(findResult(i))


def solve(n):
	ans = 0
	while n > 0:
		ans += n
		n >>= 1
	return ans
tc = int(input())
while tc > 0:
	print(solve(int(input())))
	tc -= 1


map = {}
map[1] = 1
i = 2
while i < 10 ** 18 + 10:
	map[i] = map[i // 2] * 2 + 1
	i = i * 2
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	i = 0
	while n > 0:
		if n % 2 == 1:
			ans += map[pow(2, i)]
		i += 1
		n = n // 2
	print(ans)


for _ in range(int(input())):
	n = int(input())
	i = 1
	j = 2
	c = 0
	while j // 2 <= n:
		c += i * ((n - j // 2) // j + 1)
		i += 1
		j *= 2
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	res = 0
	p = n
	while n != 0:
		res += n // 2
		n = n // 2
	print(p + res)


from sys import stdin, stdout
import sys
from math import *
for __ in range(int(input())):
	n = int(input())
	c = 0
	a = [0]
	for i in range(1, len(bin(n)[2:]) + 1):
		if 2 ** i <= n:
			c = c * 2 + i
			a.append(c)
	s = bin(n)[2:]
	a = a[::-1]
	ans = 0
	for i in range(len(s)):
		if s[i] == '1':
			ans += a[i] + len(s) - i
	print(ans)


import sys
import math
import random

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def linput():
	return list(input())

def rinput():
	return map(int, tinput())

def rlinput():
	return list(map(int, input().split()))

def srlinput():
	return sorted(list(map(int, input().split())))

def main():

	def pro(x):
		w = []
		while x != 1:
			w.append(x % 2)
			x //= 2
		w.append(1)
		w.reverse()
		return w
	n = iinput()
	res = 0
	t = pro(n)
	l = len(t)
	for i in range(len(t)):
		if t[i]:
			res += p[l - i - 1]
	print(res)
p = [1 for i in range(100)]
s = 1
for i in range(1, 70):
	s *= 2
	s += 1
	p[i] = s
for inytd in range(iinput()):
	main()


t = int(input())
l = [1]
for i in range(60):
	l.append(l[-1] * 2 + 1)
for q in range(t):
	n = bin(int(input()))[2:]
	le = len(n)
	s = 0
	for i in range(le):
		s += l[le - i - 1] * int(n[i])
	print(s)


def sol(n):
	if n == 1 or n == 0:
		return n
	i = 1
	while i <= n:
		i *= 2
	return i - 1 + sol(n - i // 2)
for _ in range(int(input())):
	n = int(input())
	print(sol(n))


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		ans = 0
		t = n
		while t != 0:
			ans += t
			t = t // 2
		print(ans)
main()


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	M = N.bit_length()
	ans = 0
	for i in range(M):
		ans += N // 2 ** i
	print(ans)


c = []
for i in range(100):
	c.append(2 ** i)
rw = int(input())
for ewq in range(rw):
	n = int(input())
	f = 0
	for i in range(100):
		f += n // c[i]
	print(f)


import math
t = int(input())
for i in range(t):
	n = int(input())
	arr = []
	while n > 0:
		i = n % 2
		n = n // 2
		arr.append(i)
	summ = 0
	for i in range(len(arr)):
		if arr[i] == 1 and i != 0:
			summ = summ + pow(2, i + 1) - 1
		elif arr[i] == 1:
			summ = summ + 1
	print(summ)


import math
t = int(input())
for i in range(t):
	n = int(input())
	k = 1
	count = 0
	while n // k > 0:
		count += n // k
		k *= 2
	print(count)


def main():
	t = int(input())
	for _ in range(t):
		x = int(input())
		k = 1
		s = 0
		while x != 0:
			r = x % 2
			x = x // 2
			s += (x + r) * k
			k += 1
		print(s)
main()


from math import log
for _ in range(int(input())):
	n = int(input())
	count = 0
	for i in range(int(log(n, 2)) + 1):
		count += n // 2 ** i
	print(count)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	div = 1
	while n // div > 0:
		ans += n // div
		div *= 2
	print(ans)


for _ in range(int(input())):
	n = int(input())
	ans = 0
	temp = 1
	for i in range(1, 65):
		ans += (n + 1) // temp
		if (n + 1) % temp == 0:
			ans -= 1
		temp = temp * 2
	print(ans)


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def mod():
	return 10 ** 9 + 7
for _ in range(INT()):
	n = INT()
	a = bin(2 * n)[2:]
	aa = a.count('1')
	ans = 2 * n - aa
	print(ans)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N):
	total = 0
	for i in range(62):
		total += N // 2 ** i
	return total
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	ans = solve(N)
	print(ans)


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def output(*args):
	sys.stdout.buffer.write(('\n'.join(map(str, args)) + '\n').encode('utf-8'))

def main():
	t = int(input())
	ans_a = [''] * t
	for ti in range(t):
		n = int(input())
		ans = 0
		while n:
			ans += n
			n >>= 1
		ans_a[ti] = str(ans)
	output(*ans_a)
main()


from sys import stdin as cin
from math import log, floor
lmap = lambda f, v: list(map(f, v))
MAX_N = 10 ** 18
MAX_LOG2 = floor(log(MAX_N, 2))
POW2 = [2 ** i for i in range(MAX_LOG2 + 1)]

def not_honest(n):
	c = 0
	for p in reversed(POW2):
		if n >= p:
			c += p * 2 - 1
			n -= p
	return c

def main():
	t = int(next(cin).strip())
	for i in range(t):
		n = int(next(cin).strip())
		print(not_honest(n))
main()


def aaaa(xxx):
	if xxx <= 0:
		return 0
	return xxx % 2 + aaaa(xxx // 2)

def aaa(xxx):
	ba = 0
	for j in range(1, xxx + 1):
		ba += aaaa(j)
	return ba
x = int(input())
for xxx in range(x):
	number = int(input())
	if number == 1:
		print(1)
	else:
		print(number * 2 - aaaa(number))


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
calc = [1]
for i in range(1, 65):
	calc.append(calc[i - 1] * 2 + (i + 1))

def poof(n):
	(l, r) = (0, 100)
	while r - l > 1:
		m = (r + l) // 2
		if (1 << m) - 1 <= n:
			l = m
		else:
			r = m
	return l

def magic(n):
	x = poof(n)
	out = calc[x]
	while x:
		y = (1 << x) - 1
		if n == y:
			out -= calc[x - 1]
			break
		elif n > y:
			n -= y + 1
		elif n < y:
			out -= calc[x - 1] + (x + 1)
		x -= 1
	return out
t = int(input())
for _ in range(t):
	n = int(input())
	print(magic(n - 1))


from sys import stdin, stdout
dp = [0]
for i in range(1, 60):
	dp.append(2 * dp[i - 1] + i)
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	if n == 1:
		print(1)
		continue
	else:
		b = bin(n)[2:]
		l = len(b)
		ans = 0
		for i in range(l):
			if b[i] == '1':
				j = l - i
				ans += j + dp[j - 1]
		print(ans)


import math
t = int(input())
for i in range(t):
	n = int(input())
	prev_total = -1
	total = 0
	cnt = 0
	while total != prev_total:
		prev_total = total
		total += math.ceil(n >> cnt)
		cnt += 1
	print(total)


class Solution:

	def __init__(self):
		for t in range(int(input())):
			n = int(input())
			self.solve(n)

	def solve(self, n):
		b = format(n, 'b')
		res = 0
		while b:
			res += int(b, 2)
			b = b[:-1]
		print(res)
Solution()


t = int(input())
from math import log
for i in range(t):
	n = int(input())
	ans = (n + 1) // 2
	for j in range(1, 60):
		if 2 ** j > n:
			break
		a = 2 ** j
		c = n // a
		if c % 2:
			c = c // 2 + 1
		else:
			c = c // 2
		ans += c * (j + 1)
	print(ans)


tests = int(input())
for i in range(tests):
	n = int(input())
	x = 0
	res = 2 ** x - 1
	result = 0
	while res < n:
		if (n - res) % 2 ** (x + 1) == 0:
			result += (x + 1) * ((n - res) // 2 ** (x + 1))
		else:
			result += (x + 1) * ((n - res) // 2 ** (x + 1) + 1)
		x += 1
		res = 2 ** x - 1
	print(result)


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(input())
while t:
	t -= 1
	n = int(input())
	s = 0
	for i in range(len(bin(n)) - 2):
		s += n // (1 << i)
	print(s)


def diff(a, b):
	masked = a ^ b
	s = '{0:b}'.format(masked)
	ret = len([c for c in s if c == '1'])
	return ret

def ans(n):
	ret = 0
	for i in range(0, n):
		ret += diff(i, i + 1)
	return ret

def fast_ans(n):
	s = '{0:b}'.format(n)
	return 2 * n - len([c for c in s if c == '1'])
T = int(input())
for t in range(T):
	n = int(input())
	print(fast_ans(n))


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *
base = [0] * 62
base[0] = 1
for i in range(1, 62):
	base[i] = 2 * base[i - 1] + 1

def fx(x):
	global base
	k = 0
	i = 61
	rs = 0
	while i >= 0:
		if k + (1 << i) <= x:
			rs = rs + base[i]
			k += 1 << i
		i -= 1
	return rs

def main():
	ntest = int(stdin.readline())
	for testcase in range(ntest):
		n = int(stdin.readline())
		res = fx(n)
		stdout.write('%d\n' % res)
	return 0
main()


def answer():
	n = map(int, list(bin(int(input())))[-1:1:-1])
	return sum([2 ** i * 2 - 1 for (i, ni) in enumerate(n) if ni])
for _ in range(int(input())):
	print(answer())


T = int(input())
for t_itr in range(T):
	N = int(input())
	mult = 1
	result = 0
	while N > 0:
		num = (N + 1) // 2
		result += num * mult
		mult += 1
		N -= num
	print(result)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	i = 1
	c = n
	while n > 0:
		if n % 2 == 0:
			x = n // 2
		else:
			x = n // 2 + 1
		ans += i * x
		n = n - x
		i += 1
	print(ans)


def dfg(n):
	if n > 0:
		return n + dfg(n // 2)
	else:
		return 0
t = int(input())
for j in range(0, t):
	k = int(input())
	if k == 0:
		print(0)
	else:
		print(dfg(k))


t = int(input())
while t != 0:
	n = int(input())
	ans = 0
	for i in bin(n)[2:]:
		if i == '1':
			ans += 1
	print(n * 2 - ans)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	res = n
	j = 1
	while n >= j:
		res += n // (2 * j)
		j *= 2
	print(res)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial, ceil
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		n = N()
		res = 0
		while n > 0:
			res += n
			n >>= 1
		print(res)
main()


from sys import stdin
input = stdin.buffer.readline

def f(n):
	return f(n >> 1) + n if n != 1 else 1
for _ in range(int(input())):
	print(f(int(input())))


from sys import stdin
input = stdin.buffer.readline

def rec(n):
	if n == 1:
		return 1
	return n + rec(n // 2)
for _ in range(int(input())):
	n = int(input())
	print(rec(n))


T = int(input())

def process(x):
	ans = 0
	pos = 0
	while x:
		t = x & 1
		x //= 2
		if t > 0:
			ans += 2 * 2 ** pos - 1
		pos += 1
	return ans
for _ in range(T):
	n = int(input())
	print(process(n))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	count = int(math.log2(n)) + 1
	res = 0
	for i in range(1, count + 1):
		res += i
		nume = n - 2 ** (i - 1)
		res += nume // 2 ** i * i
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	a = len(bin(n)[2:])
	ans = 0
	j = 1
	for i in range(a):
		ans += n // j
		j = j * 2
	print(ans)


import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline

def geta(fn=lambda s: s.decode()):
	return map(fn, readline().split())

def gete(fn=lambda s: s.decode()):
	return fn(readline().rstrip())

def main():
	for _ in range(gete(int)):
		n = gete(int)
		(b, ans) = (1, 0)
		while b <= n:
			ans += n // b
			b *= 2
		print(ans)
main()


t = int(input())
while t:
	n = int(input())
	x = bin(2 * n)[2:]
	y = x.count('1')
	print(2 * n - y)
	t = t - 1


import sys
try:
	t = int(input())
	for _ in range(t):
		n = int(input())
		x = n
		s = 0
		n = bin(n)
		n = n.lstrip('0b')
		p = 1
		for i in range(len(n)):
			s += x // p
			p *= 2
		print(s)
except EOFError:
	pass


t = int(input())
for test in range(t):
	n = int(input())
	bits = []
	if n == 0:
		print(0)
		continue
	while n > 0:
		bits.append(n % 2)
		n = n // 2
	bits.reverse()
	changes = bits.copy()
	for i in range(1, len(changes)):
		changes[i] += 2 * changes[i - 1]
	print(sum(changes))


for _ in range(int(input())):
	n = int(input())
	if n == 0:
		print(0)
	elif n == 1:
		print(1)
	else:
		if n % 2 == 0:
			odd = n // 2
		else:
			odd = (n - 1) // 2 + 1
		cnt = odd
		mul = 2
		i = 2
		while i <= n:
			cnt += mul * ((n - i) // (i * 2) + 1)
			mul += 1
			i *= 2
		print(cnt)


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

class Node:

	def _init_(self, val):
		self.data = val
		self.left = None
		self.right = None

class fen_tree:

	def __init__(self, list):
		self.array = [0] + list
		for idx in range(1, len(self.array)):
			idx2 = idx + (idx & -idx)
			if idx2 < len(self.array):
				self.array[idx2] += self.array[idx]

	def prefix_query(self, idx):
		result = 0
		while idx:
			result += self.array[idx]
			idx -= idx & -idx
		return result

	def prints(self):
		print(self.array)
		return

	def range_query(self, from_idx, to_idx):
		return self.prefix_query(to_idx) - self.prefix_query(from_idx - 1)

	def update(self, idx, add):
		while idx < len(self.array):
			self.array[idx] += add
			idx += idx & -idx

def pre_sum(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def pre_back(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def bin_search(arr, l, r, val):
	if arr[r] <= val:
		return r + 1
	if r - l < 2:
		if arr[l] > val:
			return l
		else:
			return r
	mid = int((l + r) / 2)
	if arr[mid] <= val:
		return bin_search(arr, mid, r, val)
	else:
		return bin_search(arr, l, mid, val)

def search_leftmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[l] == val:
			return l
		if r - l <= 1:
			if arr[r] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] >= val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def search_rightmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[r] == val:
			return r
		if r - l <= 1:
			if arr[l] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] > val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def preorder_postorder(root, paths, parent, left, level):
	l = 0
	queue = [root]
	while queue != []:
		node = queue[-1]
		flag = 0
		for i in paths[node]:
			if i != parent[node] and level[i] == sys.maxsize:
				parent[i] = node
				level[i] = level[node] + 1
				flag = 1
				queue.append(i)
		if flag == 0:
			left[parent[node]] += 1 + left[node]
			queue.pop()
	return [parent, left, level]

def nCr(n, r, p):
	if r == 0:
		return 1
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def make_tree(n):
	root = 1
	paths2 = [[] for i in range(n + 1)]
	parent = [0 for i in range(n + 1)]
	for i in range(n - 1):
		[p, child] = inlt()
		paths2[p].append(child)
		paths2[child].append(p)
	path = [[] for i in range(n + 1)]
	root = 1
	queue = [root]
	parent[1] = -1
	while queue != []:
		curr = queue.pop(0)
		for i in paths2[curr]:
			if parent[i] == 0:
				parent[i] = curr
				queue.append(i)
				path[curr].append(i)
	parent[1] = 0
	return [path, parent]

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	ans = 0
	for test in range(tests):
		n = inp()
		ans = 0
		curr = 1
		while curr <= n:
			ans = ans + n // curr
			curr = curr * 2
		print(ans)
main()


for testcase in range(int(input())):
	n = int(input())
	logs = []
	i = 1
	while i <= n:
		logs.append(i)
		i *= 2
	unfair = 0
	for log in logs:
		unfair += n // log
	print(unfair)


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def solve():
	n = ri()
	ret = 0
	p = 1
	while p <= n:
		ret += n // p
		p *= 2
	print(ret)
	return
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


from sys import stdin, stdout
import heapq as hq
from collections import defaultdict
mem = {0: 0, 1: 1}

def fn(x):
	if x in mem:
		return mem[x]
	else:
		res = fn(x // 2) + x
		mem[x] = res
		return res
t = int(input())
for tc in range(t):
	n = int(stdin.readline())
	res = fn(n)
	stdout.write(str(res) + '\n')


import math

def tc():
	n = int(input())
	p = int(math.log2(n))
	ans = 0
	for i in range(p + 1):
		ans += n // 2 ** i
	return ans
T = int(input())
for _ in range(T):
	ans = tc()
	print(ans)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	print(2 * n - bin(n).count('1'))


import sys
input = sys.stdin.readline
from collections import *
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	now = 2
	while now <= 2 * n:
		ans += 2 * n // now
		now *= 2
	print(ans)


from collections import deque
from sys import stdin, stdout
import math
input = stdin.readline
vals = [0] * 62
vals[1] = 1
sm = 1
for i in range(2, 62):
	vals[i] = sm + i
	sm += vals[i]
for _ in range(int(input())):
	x = int(input())
	bit = 1
	res = 0
	for (ind, i) in enumerate(str(bin(x))[2:][::-1]):
		if i == '1':
			res += vals[ind + 1]
	print(res)


import math
T = int(input())
for _ in range(T):
	n = int(input())
	Sum = 0
	while n > 0:
		Sum += n
		n = n // 2
	print(Sum)


t = int(input())
for i in range(t):
	n = int(input())
	temp = bin(n)[2:len(bin(n))]
	t = len(temp)
	sum = 0
	for j in range(t):
		sum += n // 2 ** j
	print(sum)


from sys import stdin
from math import floor

def func(n, i):
	x = pow(2, i)
	y = x // 2
	return i * ((n - y) // x + 1)
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	count = 0
	i = 1
	while i < 63:
		count += func(n, i)
		i += 1
	print(count)


tests = int(input())
for _ in range(tests):
	n = int(input())
	x = 2
	a = [0] * 11
	y = 10
	t = 1
	ans = 0
	while n + x // 2 >= x:
		z = (n + x // 2) // x
		ans += t * z
		t += 1
		x = pow(2, t)
	print(ans)


from sys import stdin
from math import log, ceil

def list_input():
	return list(map(int, input().split()))

def sep_input():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	f = ceil(log(n, 2))
	ans = 0
	for i in range(0, f + 1):
		ans += n // 2 ** i
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	ans = 0
	for i in range(0, 60):
		val = 1 << i
		temp = (n + 1) // val
		if (n + 1) % val != 0:
			temp += 1
		ans += temp - 1
	print(ans)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
for ii in range(int(input())):
	n = int(input())
	b = bin(n)[2:]
	l = len(b)
	ans = 0
	for i in range(len(b)):
		if i == l - 1:
			if i == '1':
				ans += 1
				break
		if b[i] == '1':
			pos = l - i
			ans += pow(2, pos) - 1
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	ans = 0
	count = 1
	while n > 0:
		if n % 2 == 1:
			temp = 1
		else:
			temp = 0
		n = n // 2
		ans += count * (n + temp)
		count += 1
	print(ans)


import math
Q = int(input())
for i in range(Q):
	n = int(input())
	ans = [1]
	a = 1
	t = 1
	while True:
		t1 = 2 ** a
		if t1 > n:
			break
		else:
			t = 2 * t + 1
			ans.append(t)
			a += 1
	res = ans[-1]
	y = n - 2 ** (len(ans) - 1)
	y = bin(y)[2:][::-1]
	for i in range(len(y)):
		if y[i] == '1':
			res += ans[i]
	print(res)


from functools import lru_cache

@lru_cache(None)
def dp(i):
	if i == 0:
		return 1
	return 2 * dp(i - 1) + (i - 1)

def solve(n):
	if n == 0:
		return 0
	if n == 1:
		return 1
	i = 0
	while 1 << i + 1 <= n:
		i += 1
	if (1 << i) - 1 == n:
		return dp(i)
	return dp(i) + i + solve(n - (1 << i))
t = int(input())
for _ in range(t):
	n = int(input())
	print(solve(n))


t = int(input())
for _ in range(t):
	n = int(input())
	s_m = 0
	while n:
		s_m += n
		n //= 2
	print(s_m)


def readintlst():
	return list(map(int, input().split(' ')))

def readn():
	return int(input())
for _ in range(readn()):
	n = readn()
	ans = 0
	while n >= 1:
		ans += n
		n //= 2
	print(ans)


from math import *
from collections import *
from operator import itemgetter
import bisect
from heapq import *
i = lambda : input()
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
I = lambda : list(map(int, input().split()))
chrIdx = lambda x: ord(x) - 96
idxChr = lambda x: chr(96 + x)
t = ii()

def find(x):
	y = bin(x + 1)[2:]
	x = bin(x)[2:]
	x = '0' * (len(y) - len(x)) + x
	c = 0
	for i in range(len(y)):
		if x[i] != y[i]:
			c += 1
	return c
for _ in range(t):
	n = ii()
	ans = 0
	x = 2 ** 3
	i = 3
	while x <= 10 ** 20:
		ans += n // x * i
		if n % x >= x // 2:
			ans += i
		x *= 2
		i += 1
	ans += 4 * (n // 4)
	if n % 4 > 0:
		l = [1, 2, 1]
		ans += sum(l[:n % 4])
	print(ans)


import sys, math
input = sys.stdin.readline
t = int(input())
d = {}
for i in range(61):
	current = 2 ** i
	d[current] = 2 * current - 1
for r in range(t):
	n = int(input())
	binary = bin(n)[2:]
	binary = binary[::-1]
	ans = 0
	for i in range(len(binary)):
		if binary[i] == '1':
			ans += d[2 ** i]
	print(ans)


import math
we = int(input())
w = 1000000000000000000
s = list(bin(w).replace('0b', ''))
arr = [0] * (len(s) + 1)
for i in range(1, len(s) + 1):
	arr[i] = 2 * arr[i - 1] + i
for erw in range(we):
	n = int(input())
	s = list(bin(n).replace('0b', ''))
	ans = 0
	for i in range(len(s)):
		if i == len(s) and s[i] == '1':
			ans += 1
		elif s[i] == '1':
			ans += arr[len(s) - i - 1] + len(s) - i
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	bin_string = bin(n)
	value = 0
	for i in bin_string:
		if i == '1':
			value += 1
	print(2 * n - value)


import sys, math
from collections import deque

def solve():
	n = int(input())
	s = bin(n)[2:]
	total = 0
	runningS = 1
	x = 1
	for i in range(len(s) - 1, -1, -1):
		if s[i] == '1':
			total += runningS
		x *= 2
		runningS += x
	print(total)
	return
for _ in range(int(input())):
	solve()


t = int(input())
import math
for t1 in range(0, t):
	n = int(input())
	x = bin(n)
	ans = 2 * n - x.count('1')
	print(ans)


import sys, math
input = sys.stdin.readline
A = []
for i in range(61):
	A.append(2 ** i)
T = int(input())
for _ in range(T):
	n = int(input())
	s = 0
	i = 0
	while i <= math.floor(math.log2(n)):
		s = s + (i + 1) * ((n - A[i]) // A[i + 1] + 1)
		i = i + 1
	print(s)


arr = []
for j in range(69):
	arr.append(2 ** (j + 1) - 1)
lis = [0]
for j in range(60):
	lis.append(arr[j] + lis[-1])
t = int(input())
for i in range(t):
	n = int(input())
	a = bin(n)
	a = a[2:]
	s = len(a)
	ans = lis[s - 1] + s
	k = 0
	for j in range(1, s):
		if a[j] == '1' and k == 0:
			k += 1
			ans += lis[s - j]
		if a[j] == '0' and k == 1:
			ans -= lis[s - j]
			k -= 1
	print(ans)


from math import log2 as l
for _ in range(int(input())):
	(n, res) = (int(input()), 0)
	for i in range(60):
		if n & 1 << i:
			res += (1 << i + 1) - 1
	print(res)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	for x in range(1, int(math.log(n, 2)) + 2):
		ans += int(x * ((n + 2 ** (x - 1)) // 2 ** x))
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	c = 1
	while c <= n:
		ans += n // c
		c *= 2
	print(ans)


import sys
from math import log
from collections import *
ip = lambda : sys.stdin.readline().rstrip()
for test in range(int(ip())):
	n = int(ip())
	ans = 2 * n
	while n:
		if n & 1:
			ans -= 1
		n >>= 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	diffs = 0
	i = 2
	adds = n
	while adds > 0:
		diffs += adds
		adds = n // i
		i *= 2
	print(diffs)


import math
t = int(input())

def precalc(max_n):
	ans = {}
	for i in range(1, max_n + 1):
		ans[i] = (2 ** i - 1, 2 ** (i - 1))
	return ans
mp = precalc(60)

def calc_len(n, begin):
	return n - begin + 1

def calc_increase(d, l, k):
	return (1 + (l - 1) // (d + 1)) * k
for i in range(t):
	n = int(input())
	ans = 0
	if n == 1:
		print(1)
		continue
	max_k = int(math.floor(math.log(n, 2) + 1))
	for k in range(1, max_k + 1):
		(dist, begin) = mp.get(k)
		ans += calc_increase(dist, calc_len(n, begin), k)
	print(ans)


t = int(input())
for o in range(t):
	n = int(input())
	bitLength = 0
	m = n
	while m > 0:
		bitLength += 1
		m = m // 2
	divider = 1
	ans = 0
	for i in range(bitLength):
		ans += n // divider
		divider = divider * 2
	print(ans)


import math
II = lambda : int(input())
for _ in range(II()):
	n = II()
	k = int(math.log2(n))
	print(sum([n // (1 << i) for i in range(k + 1)]) + int(n == 1 << k + 1))


import sys
from collections import defaultdict as dd
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	n = int(input())
	w = len(bin(n)) - 2
	a = [0]
	for i in range(1, w + 2):
		a.append(2 * a[i - 1] + 1)
	s = 0
	while n > 0:
		k = len(bin(n)) - 2
		n -= int('1' + '0' * (k - 1), 2)
		s += a[k]
	print(s)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	N = int(input())
	bn = list(bin(N))[2:]
	bn.reverse()
	res = 0
	for i in range(len(bn)):
		res += (bn[i] == '1') * (pow(2, i + 1) - 1)
	print(res)


from collections import Counter, defaultdict
BS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def to_base(s, b):
	res = ''
	while s:
		res += BS[s % b]
		s //= b
	return res[::-1] or '0'
alpha = 'abcdefghijklmnopqrstuvwxyz'
from math import floor, ceil
from math import log2
t = int(input())
for i in range(t):
	n = int(input())
	tot = 0
	cur = 1
	while cur <= n:
		tot += n // cur
		cur *= 2
	print(tot)


d = {}
d[1] = 1
i = 2
while i <= 1e+18:
	d[i] = d[i // 2] * 2 + 1
	i *= 2
for _ in range(int(input())):
	n = int(input())
	ans = 0
	i = 0
	while n > 0:
		if n % 2 == 1:
			ans += d[2 ** i]
		i += 1
		n //= 2
	print(ans)


for _ in range(int(input())):
	n = int(input())
	i = 1
	count = 0
	while i <= n:
		count += n // i
		i *= 2
	print(count)


for _ in range(int(input())):
	num = int(input())
	print(2 * num - bin(num).count('1'))


import math

def lpow(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p
preb = [0] * 60
preb[1] = 1
for i in range(2, 60):
	preb[i] += 2 * preb[i - 1] + i
for xyz in range(0, int(input())):
	n = int(input())
	a = 0
	while n > 0:
		ind = lpow(n) + 1
		a += preb[ind - 1] + ind
		n -= 2 ** (ind - 1)
	print(a)


T = int(input())
for t in range(T):
	n = int(input())
	powers = 0
	i = 1
	res = 0
	added = 0
	while True:
		power_2 = 2 ** i
		if power_2 > n:
			break
		r = n // power_2
		res += r
		i += 1
		powers += r
	res += n
	print(res)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2

def solve(n):
	if n == 0:
		return 0
	else:
		return solve(n // 2) + n
from math import *
for _ in range(int(input())):
	n = int(input())
	print(solve(n))


def f():
	n = int(input())
	ans = 0
	for i in range(0, 62):
		if 1 << i & n == 1 << i:
			ans += (1 << i + 1) - 1
	print(ans)
n = int(input())
for i in range(n):
	f()


import sys
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def read():
	tc = 0
	if tc:
		input = sys.stdin.readline
	else:
		sys.stdin = open('input1.txt', 'r')
		sys.stdout = open('output1.txt', 'w')

def powermod(a, b, m):
	a %= m
	res = 1
	if a == 0:
		return 0
	while b > 0:
		if b & 1:
			res = res * a % m
		b = b >> 1
		a = a * a % m
	return res

def isprime(n):
	if n <= 1:
		return 0
	for i in range(2, int(sqrt(n)) + 1):
		if n % i == 0:
			return 0
	return 1

def solve():
	f = [0] * 66
	f[0] = 1
	for i in range(1, 66):
		f[i] = 2 * f[i - 1] + 1
	for _ in range(ii()):
		n = ii()
		s = bin(n)[2:]
		s = list(s)
		ans = 0
		s.reverse()
		for i in range(len(s)):
			if s[i] == '1':
				ans += f[i]
		print(ans)
solve()


import math

def length(number):
	return int(math.log(number) / math.log(2) + 1)
for _ in range(int(input())):
	n = int(input())
	c = 0
	l = length(n)
	ad = 0
	ans = 0
	while l >= 1:
		st = pow(2, l - 1)
		if n >= st:
			n = n % st
			ans += pow(2, l) - 1
		l -= 1
	print(ans)


from math import inf as inf
from math import *
from collections import *
import sys
input = sys.stdin.readline
t = int(input())
pre = [1]
for i in range(1, 63):
	pre.append(pre[-1] * 2)
while t:
	t -= 1
	n = int(input())
	s = 0
	c = 1
	ind = 0
	while 1:
		d = n // pre[ind]
		d1 = n // pre[ind + 1]
		if not d:
			break
		s += (d - d1) * c
		ind += 1
		c += 1
	print(s)


from math import log2, floor
pow2 = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976]

def countSetBits(n):
	count = 0
	while n:
		count += n & 1
		n >>= 1
	return count
for _ in range(int(input())):
	n = int(input())
	print(2 * n - countSetBits(n))


from math import log2
t = int(input())
for _ in range(t):
	n = int(input())
	ct = 0
	for i in range(int(log2(n)) + 1):
		ct += n // 2 ** i
	print(ct)


def read_int():
	return int(input())
t = read_int()
ans = []
for case_num in range(t):
	n = int(input())
	ans.append(n * 2 - bin(n).count('1'))
print('\n'.join(map(str, ans)))


for _ in ' ' * int(input()):
	a = int(input())
	ans = 0
	for i in range(0, 62):
		if a & 1 << i:
			ans += 2 * 2 ** i - 1
	print(ans)


import sys
ints = (int(x) for x in sys.stdin.read().split())
sys.setrecursionlimit(3000)

def main():
	ntc = next(ints)
	for tc in range(1, ntc + 1):
		n = next(ints)
		b = [int(x) for x in bin(n)[2:]]
		k = len(b)
		ans = 0
		for i in range(k):
			if b[i]:
				ans += 2 ** (k - i) - 1
		print(ans)
	return
main()


t = int(input())
for i in range(t):
	n = int(input())
	cnt = 0
	str1 = bin(n)
	for j in range(len(str1)):
		if str1[j] == '1':
			cnt += 1
	print(2 * n - cnt)


import sys
import math
from collections import defaultdict

def solve(test):
	n = int(input())
	up = int(math.log(n, 2))
	ans = n // 2 + (1 if n & 1 else 0)
	prev = 0
	while up > 0:
		r = 2 ** up
		ans += (n // r - prev) * (up + 1)
		prev = n // r
		up -= 1
	print(ans)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


import sys
import math
from decimal import *

def solve(n):
	if n == 0:
		return 0
	return solve(n // 2) + n
t = int(sys.stdin.readline().strip())
for i in range(t):
	n = int(sys.stdin.readline().strip())
	print(solve(Decimal(n)))


d = {}

def func(n):
	try:
		return d[n]
	except:
		if n == 0:
			d[n] = 0
			return 0
		if n == 1:
			d[n] = 1
			return 1
		d[n] = 2 * func(n - 1) + 1
		return d[n]
for tt in range(int(input())):
	n = int(input())
	l = bin(n)[2:]
	ans = 0
	n2 = len(l)
	for i in l:
		ans += int(i) * func(n2)
		n2 -= 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	(p2, add) = (1, 1)
	ans = 0
	while p2 <= n:
		ans += (1 + (n - p2) // (2 * p2)) * add
		p2 *= 2
		add += 1
	print(ans)


q = int(input())
for z in range(q):
	n = int(input())
	k = 1
	r = 0
	while n // k != 0:
		r += n // k
		k *= 2
	print(r)


for t in range(int(input())):
	n = int(input())
	s = 0
	m = 1
	while n >= m:
		if n & m != 0:
			s += 2 * m - 1
		m *= 2
	print(s)


import math

def f(n):
	return 2 ** (n + 1) - 1
t = int(input())
for i in range(t):
	n = int(input())
	sumi = 0
	while n > 0:
		msb = n.bit_length() - 1
		sumi += (1 << msb + 1) - 1
		n ^= 1 << msb
	print(sumi)


from bisect import bisect_right
pref = [1]
pows = [1]
for i in range(65):
	pref.append(pref[-1] * 2 + 1)
	pows.append(pows[-1] * 2)

def solve(n):
	ans = 0
	while n > 0:
		p = bisect_right(pows, n)
		ans += pref[p - 1]
		n = n - pows[p - 1]
	return ans
inp = input
for _ in range(int(inp())):
	n = int(inp())
	print(solve(n))


from sys import stdin, stdout
read = stdin.readline

def puts(x, end='\n'):
	stdout.write(x + end)

def read_int():
	return int(read())

def list_in():
	return [i for i in read().split()]

def int_list_in():
	return [int(i) for i in read().split()]

def solve():
	n = read_int()
	total = 0
	for (index, bit) in enumerate(reversed(bin(n)[2:])):
		if bit == '1':
			total += 2 ** (index + 1) - 1
	print(total)
for i in range(read_int()):
	solve()


import sys
from math import log2, floor, ceil, sqrt
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def solve(n):
	arr = []
	while n > 0:
		arr.append(n % 2)
		n = n // 2
	return arr
for _ in range(int(ri())):
	n = int(ri())
	arr = solve(n)
	ans = 0
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] == 1:
			ans += 2 ** (i + 1) - 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase

def inputIntArray():
	return list(map(int, input().rstrip().split()))

def inputArray():
	return input().rstrip().split()

def inputVars():
	return map(int, input().rstrip().split())

def inputNum():
	return int(input())

def main():
	for _ in range(inputNum()):
		n = inputNum()
		ans = 0
		for bitPos in range(60):
			if n & 1 << bitPos:
				ans += (1 << bitPos + 1) - 1
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys, collections, math

def in_out():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n:
		ans += n
		n = n // 2
	print(ans)


def solve():
	n = int(input())
	res = 0
	i = 1
	while n:
		if n & 1:
			res += i + i - 1
		n >>= 1
		i *= 2
	print(res)
for _ in range(int(input())):
	solve()


import math
from decimal import *
getcontext().prec = 30
t = int(input())
while t:
	t -= 1
	n = int(input())
	ans = 0
	i = 0
	while n:
		if n % 2:
			ans += pow(2, i + 1) - 1
		n = n // 2
		i += 1
	print(ans)


import sys
input = sys.stdin.buffer.readline
t = int(input())
while t:
	t -= 1
	ans = 0
	n = int(input())
	while n >= 1:
		ans += n
		n = n // 2
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	w = [n // 2 ** i for i in range(70)]
	print(sum(w))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from bisect import bisect
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def csb(n):
	count = 0
	while n:
		count += n & 1
		n >>= 1
	return count

def solve():
	helper = [1 << i for i in range(0, 63)]
	for _ in range(int(input())):
		n = int(input())
		ans = 0
		while n:
			ind = bisect(helper, n)
			ans += helper[ind - 1] * 2 - 1
			n -= helper[ind - 1]
		print(ans)
solve()


def split(word):
	return [char for char in word]
powersof2 = []
current = 1
for i in range(100):
	powersof2.append(current)
	current = 2 * current + 1
t = int(input())
for i in range(t):
	n = int(input())
	s = '{0:b}'.format(n)
	a = split(s)
	a.reverse()
	ans = 0
	for j in range(len(a)):
		if a[j] == '1':
			ans += powersof2[j]
	print(ans)


for u in range(int(input())):
	n = int(input())
	a = 0
	ans = 1
	while n != 0:
		r = n // 2
		x = n % 2
		a += ans * (r + x)
		n = n // 2
		ans += 1
	print(a)


D = {}
i = 1
while i < 1e+18:
	D[i] = i ^ i - 1
	i = i * 2
for _ in range(int(input())):
	a = int(input())
	c = 0
	s = 0
	while a > 0:
		s = s + a % 2 * D[2 ** c]
		a = a // 2
		c = c + 1
	print(s)


nb = int(input())
compteur = 0
for loop in range(nb):
	num = int(input())
	p = 1
	while num // p > 0:
		compteur += num // p
		p *= 2
	print(compteur)
	p = 1
	compteur = 0


cas = int(input())
for i in range(cas):
	n = int(input())
	no = 1
	ans = 0
	while no <= n:
		ans += n // no
		no <<= 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = n.bit_length() - 1
	ans = 0
	for i in range(l, -1, -1):
		x = n // (1 << i)
		y = n // (1 << i + 1)
		ans += (x - y) * (i + 1)
	print(ans)


for u in range(int(input())):
	n = int(input())
	b = bin(n)
	x = b.count('1')
	s = 2 * n
	print(s - x)


import math
for t in range(int(input())):
	n = int(input())
	a = str(bin(n))[2:]
	sum = 0
	z = len(a)
	for i in range(z):
		if a[i] == '1':
			sum += 2 * 2 ** (z - i - 1) - 1
	print(sum)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [0]
	while n != 0:
		a.append(n % 2)
		n = n // 2
	k = len(a)
	s = [0] * 64
	s[1] = 1
	s[2] = 4
	res = 0
	for i in range(3, len(a)):
		s[i] = s[i - 1] + i + s[i - 1]
	for i in range(len(a) - 1, 0, -1):
		if a[i] == 1:
			res += s[i - 1] + i
	print(res)


def main():
	t = int(input())
	for i in range(t):
		ans = 0
		k = int(input())
		num = 1
		tmp = 0
		while num * 2 - 1 < k:
			num *= 2
			tmp += 1
		if tmp == 0:
			print(1)
		else:
			k = k - 2 ** tmp + 1
			ans = ans + 2 ** (tmp + 1) - tmp - 2
			while k > 1:
				ans += tmp + 1
				k -= 1
				num = 1
				tmp = 0
				while num * 2 - 1 < k:
					num *= 2
					tmp += 1
				k = k - 2 ** tmp + 1
				ans = ans + 2 ** (tmp + 1) - tmp - 2
			if k == 0:
				print(ans)
			if k == 1:
				print(ans + tmp + 1)
main()


import math
for i1 in range(int(input())):
	n = int(input())
	p = int(math.log(n, 2))
	sum = 0
	for i in range(p + 1):
		sum = sum + n // 2 ** i
		if n // 2 ** i == 0:
			break
	print(sum)


t = int(input())
for iteration in range(0, t):
	n = int(input())
	res = 0
	for _pow in range(0, 65):
		if (n + 1) % (1 << _pow) == 0:
			res += (n + 1) // (1 << _pow) - 1
		else:
			res += (n + 1) // (1 << _pow)
	print(res)


x = int(input())
while x > 0:
	n = int(input())
	temp = bin(n)
	cnt = [i for i in temp[2:] if i == '1']
	print(2 * n - len(cnt), sep='\n')
	x -= 1


for _ in range(int(input())):
	a = int(input())
	b = bin(a)
	cont = 0
	for i in b:
		if i == '1':
			cont += 1
	print(2 * a - cont)


import sys

def input():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(int(input())):
		n = int(input())
		ans = 0
		for k in range(64, -1, -1):
			if 2 ** k <= n:
				ans += 2 ** (k + 1) - 1
				n -= 2 ** k
		print(ans)
main()


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def getStr():
	return input().strip()
d = []
d.append(1)
for i in range(1, 70):
	d.append(i + 1 + sum(d))
t = getInt()
for _ in range(t):
	n = getInt()
	n2 = bin(n)
	n2 = n2[::-1]
	n2 = n2[:-2]
	res = 0
	for i in range(len(n2)):
		if n2[i] == '1':
			res += d[i]
	print(res)


def decimalToBinary(n):
	return bin(n).replace('0b', '')
for _ in range(int(input())):
	n = int(input())
	print(n * 2 - decimalToBinary(n).count('1'))


def pow(x):
	a = 0
	(b, c) = (1, 0)
	while x >= 1:
		b *= 2
		a += 1
		if b > x:
			a -= 1
			return a
for _ in range(int(input())):
	n = int(input())
	(i1, i2) = (0, 0)
	x = n
	while x >= 1:
		a = pow(x)
		x -= 2 ** a
		i1 += 2 ** a * 2 - 1
	print(i1)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
	n = int(input())
	num = 1
	ans = 0
	while num <= n:
		ans += n // num
		num = num << 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	(ans, temp) = (0, 1)
	while 1:
		delta = n // temp
		ans += delta
		if delta == 0:
			break
		temp *= 2
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	c = 0
	for i in range(64):
		c += n // 2 ** i
	print(c)


from functools import *
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	i = 1
	ans = 0
	while i <= n:
		ans += n // i
		i <<= 1
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	ans = 2 * n - bin(n).count('1')
	print(ans)


def solve(A, B):
	count = 0
	A = int(A, 2)
	B = int(B, 2)
	for i in range(0, 61):
		if A >> i & 1 != B >> i & 1:
			count += 1
	return count
for _ in range(int(input())):
	n = int(input())
	b = bin(n)[2:]
	b = b[::-1]
	ans = 0
	for bit in range(len(b)):
		if b[bit] == '1':
			ans += 2 ** (bit + 1) - 1
	print(ans)


t = int(input())
for _ in range(t):
	x = int(input())
	p2 = 1
	ans = 0
	while p2 <= x:
		ans += x // p2
		p2 *= 2
	print(ans)


T = int(input())
D = []
for i in range(0, T):
	n = int(input())
	s = 0
	k = 0
	a = n
	while a >= 1:
		s += a
		k += 1
		a = n // 2 ** k
	D.append(s)
for i in D:
	print(i)


def csbu(x):
	if x <= 0:
		return 0
	else:
		ans = x % 2 + csbu(x // 2)
		return ans

def csb(x):
	b = 0
	for i in range(1, x + 1):
		b += csbu(i)
	return b
for _ in range(int(input())):
	n = int(input())
	if n == 1:
		print(1)
	else:
		print(n * 2 - csbu(n))


t = input()
for _ in range(int(t)):
	n = int(input())
	c = 0
	nn = n
	while nn // 2 != 0:
		nn //= 2
		c += 1
	d = 0
	for i in range(c + 1):
		d += n // 2 ** i
	print(d)


t = int(input())
k = 0
while k < t:
	n = int(input())
	ans = 0
	i = 0
	temp = n
	while temp != 0:
		i_b = temp & 1
		if i_b:
			s = pow(2, i + 1) - 1
			ans += s
		temp = temp >> 1
		i += 1
	print(ans)
	k = k + 1


from fractions import Fraction
import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
from queue import Queue

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = 1
t = iinput()
for _ in range(t):
	n = iinput()
	ans = 0
	val = 1
	for i in range(1, 65):
		ans += (n + 1) // val
		if (n + 1) % val == 0:
			ans -= 1
		val = val * 2
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	if n == 1:
		print(1)
		continue
	elif n == 2:
		print(3)
		continue
	total = n // 2
	if n % 2 == 1:
		total += 1
	b = math.log2(n)
	if b == math.ceil(b):
		b += 1
	b = math.ceil(b)
	a = math.ceil(math.pow(2, b - 1))
	arr = []
	for i in range(b - 1):
		arr.append(n // a)
		a //= 2
	total += b * arr[0]
	b -= 1
	r = b
	for i in range(1, r):
		total += b * (arr[i] - arr[i - 1])
		b -= 1
	print(total)


t = int(input())
w = [2 ** k for k in range(100)]
for i in range(t):
	n = int(input())
	z = bin(n)[2:][::-1]
	res = 0
	for j in range(len(z)):
		if z[j] == '1':
			res += w[j + 1] - 1
	print(res)


from math import log2, floor, ceil
import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	noofbits = n.bit_length()
	ans = 0
	for i in range(0, noofbits):
		k = n // (1 << i)
		ans += k
	print(ans)


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve():
	n = get_int()
	ones = bin(n)[2:].count('1')
	print(2 * n - ones)

def main():
	solve()
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


N = int(input())
for i in range(N):
	n = int(input())
	ans = 0
	for j in range(130):
		ans += n // 2 ** j
	print(ans)


import math
t = int(input())
mem = []
mem.append(0)
for i in range(1, 64):
	mem.append(i + 2 * mem[i - 1])
for i in range(t):
	n = int(input())
	a = int(math.log2(n))
	ans = 0
	for j in range(a, -1, -1):
		if 1 << j & n > 0:
			ans += mem[j]
			ans += j + 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	while n >= 2:
		count = 0
		k = n
		while k >= 2:
			k >>= 1
			count += 1
		ans += (1 << count + 1) - 1
		n -= 1 << count
	if n != 0:
		ans += 1
	print(ans)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputmatrix(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d
t = int(input())
for q in range(t):
	n = inputnum()
	N = n
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	print(2 * N - count)


from sys import stdin
input = stdin.readline
import bisect
import math
for xoxo in range(1):
	k = [1]
	for i in range(70):
		k.append(2 * k[-1] + 1)
	for _ in range(int(input())):
		n = int(input())
		x = bin(n)[2:]
		x = x[::-1]
		ans = 0
		for i in range(len(x)):
			if int(x[i]):
				ans += k[i]
		print(ans)


import math
for _ in range(int(input())):
	n = int(input()) + 1
	xx = int(math.log(n, 2)) + 1
	ans = 0
	pat = 0
	for i in range(1, xx + 1):
		left = n - 2 ** pat
		ans += i * int(abs(-left // 2 ** (pat + 1)))
		pat += 1
	print(ans)


import sys
import string
input = sys.stdin.readline
import math
t = int(input())
powers = []
for j in range(200):
	powers.append(2 ** j)
for i in range(t):
	x = int(input())
	out = 0
	for p in powers:
		if p > x:
			break
		out += x // p
	print(out)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def f(n):
	if n <= 5:
		return [0, 1, 3, 4, 7, 8][n]
	return f(n // 2) + n
for _ in range(int(input()) if True else 1):
	n = int(input())
	print(f(n))


from functools import reduce
read = input
mi = lambda dt: map(dt, read().split())
cin = lambda : int(read())
d = [0]
for i in range(1, 65):
	d.append(i + 2 * d[-1])
for _ in range(cin()):
	n = cin()
	s = bin(n)[2:]
	ans = 0
	l = len(s)
	for i in range(l):
		if s[i] == '1':
			ans += l - i
			ans += d[l - i - 1]
	print(ans)


from sys import stdin

def iinput():
	return int(stdin.readline())

def sinput():
	return input()

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
t = iinput()
while t:
	t -= 1
	n = iinput()
	a = [1, 2, 1, 3, 1, 2, 1]
	if n < 8:
		print(sum(a[:n]))
	else:
		temp = n
		ans = 0
		while n:
			ans += n & 1
			n = n >> 1
		temp = 2 * temp - ans
		print(temp)


import sys
L = [1] * 68

def preprocess():
	prev = 0
	t = 1
	i = 0
	ans = 0
	for i in range(65):
		ans += prev + t
		L[i] = ans
		prev = ans - t
		t += 1
preprocess()
input = sys.stdin.readline
from collections import defaultdict
import math
preprocess()
for _ in range(int(input())):
	N = int(input())
	if N == 1:
		print(1)
		continue
	if N == 2:
		print(3)
		continue
	count = 0
	for i in range(64, -1, -1):
		t = pow(2, i)
		if N & t:
			count += L[i]
	print(count)


for i in range(int(input())):
	num = int(input())
	ans = 0
	z = 1
	while z <= num:
		if z & num:
			ans += z * 2 - 1
		z *= 2
	print(ans)


def kk(n):
	if n == 1 or n == 0:
		return n
	else:
		tt = n // 2
		c = kk(tt) + n
		return c
import math
T = int(input())
for _ in range(0, T):
	n = int(input())
	print(kk(n))


from collections import defaultdict
arr = [1]
amn = 1
for i in range(59):
	amn = amn * 2
	arr.append(amn)
for _ in range(int(input())):
	n = int(input())
	ans = n // 4 * 4
	if n % 4 == 1:
		ans += 1
	elif n % 4 == 2:
		ans += 3
	elif n % 4 == 3:
		ans += 4
	k = n // 4
	p = 1
	i = 0
	while (k + arr[i]) // arr[i + 1] > 0:
		ans += (k + arr[i]) // arr[i + 1] * (p + 2)
		i += 1
		p += 1
	print(ans)


def read_int():
	return int(input())
t = read_int()
for case_num in range(t):
	n = int(input())
	print(n * 2 - bin(n).count('1'))


tc = int(input())
for _ in range(tc):
	x = int(input())
	div = 1
	score = 0
	while x // div >= 1:
		score += x // div
		div *= 2
	print(score)


import math as mt
import sys, string
input = sys.stdin.readline
from collections import defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
a = [0]
for i in range(1, 10 ** 5):
	a.append(a[i // 2] + i)

def fun(n):
	if n < 10 ** 5:
		return a[n]
	else:
		return fun(n // 2) + n
t = I()
for _ in range(t):
	n = I()
	print(fun(n))


t_test = int(input().strip())
while t_test > 0:
	(diff, i) = (0, 1)
	num = int(input().strip())
	while i <= num:
		if num & i != 0:
			diff += 2 * i - 1
		i *= 2
	print(diff)
	t_test -= 1


from math import log2, ceil
t = int(input())
MAXN = 1e+18
LOG2MAXN = ceil(log2(MAXN))

def solve(num):
	res = 0
	for i in range(0, LOG2MAXN):
		windowsLength = 1 << i
		adjacentDifferent = num // windowsLength
		res += adjacentDifferent
	return res
for _ in range(t):
	n = int(input())
	ans = solve(n)
	print(ans)


from math import log2
for t in range(int(input())):
	n = int(input())
	e = 0
	for j in range(int(log2(n)) + 2):
		d = n // (1 << j)
		e += int(d)
	print(e)


import sys
import math
import operator as op
from functools import reduce

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom
N = int(1000000.0) + 10
fenwick = [0] * N

def add(i, x, n):
	while i < n:
		fenwick[i] += x
		i = i | i + 1

def fsum(i, n):
	res = 0
	while i >= 0:
		res += fenwick[i]
		i = (i & i + 1) - 1
	return res

def fsum_range(i, j, n):
	return fsum(j, n) - fsum(i - 1, n)
mod = int(1000000000.0) + 7
t = read_int()
for i in range(t):
	n = read_int()
	ans = 0
	while n > 0:
		ans += n
		n = n // 2
	print(ans)


import sys, math, cmath, time
start_time = time.time()

def solve():
	ONLINE_JUDGE_SOLUTION = CodeforcesSolutions.AutoSolve('1362', 'B', 'GET', 'POST')

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
	sys.stdout.close()

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

class CodeforcesSolutions:

	def AutoSolve(contest_id, question_id, get, post):
		n = inp()
		qw = 0
		c = 0
		w = n
		i = 1
		while True:
			q = n // 2
			if n % 2 != 0:
				q = q + 1
			qw = qw + q * i
			c = c + q
			n = n - q
			if c == w:
				break
			i = i + 1
		print(qw)
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


t = int(input())
d = 1
a = [1]
for i in range(1, 65):
	a.append(a[i - 1] * 2 + 1)
for ii in range(t):
	n = int(input())
	bin = []
	while n > 0:
		bin.append(n % 2)
		n //= 2
	res = 0
	for i in range(len(bin) - 1, -1, -1):
		if bin[i] == 1:
			res += a[i]
	print(res)


f = [0] * 66
f[0] = 1
for i in range(65):
	f[i + 1] = f[i] * 2 + 1
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	for i in range(65, -1, -1):
		if n & 1 << i > 0:
			ans += f[i]
	print(ans)


cases = int(input())
arr = []
start = 0
while 2 ** start <= 10 ** 18:
	arr.append(2 ** start)
	start += 1
import math
for i in range(cases):
	n = int(input())
	end = bin(n)[2:]
	max_expo = len(end) - 1
	value = 2 ** max_expo
	s = 0
	s += n + 1
	if n == 1:
		print(1)
		continue
	for j in range(1, max_expo):
		s += n // 2 ** j
	print(s)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
from typing import List

def solve(N):
	if N <= 0:
		return 0
	if N == 1:
		return 1
	bits = 0
	v = N
	while v > 0:
		v >>= 1
		bits += 1
	ans = (N + 1) // 2
	for k in range(2, bits + 1):
		y = N - 2 ** (k - 1) + 1
		x = y >> k
		if x << k == y:
			x -= 1
		ans += (x + 1) * k
	return ans
ans = []
T = int(input())
for ti in range(T):
	N = int(input())
	ans.append(solve(N))
print('\n'.join(map(str, ans)))


for _ in range(int(input())):
	n = int(input())
	out = 0
	twop = 1
	while twop <= n:
		if twop & n:
			out += twop * 2 - 1
		twop *= 2
	print(out)


def set_bits(n):
	return bin(n).count('1')
for i in range(int(input())):
	n = int(input())
	print(2 * n - set_bits(n))


import sys
IN = [x.strip() for x in sys.stdin.readlines()]
T = int(IN[0])
vals = []
for i in range(T):
	vals.append(bin(int(IN[1 + i]))[2:])
nb = max([len(v) for v in vals])
bit2count = [2 ** i - 1 for i in range(1, nb + 1)]
for n in vals:
	n = n
	l = len(n)
	tot = 0
	for i in range(l):
		tot += bit2count[l - i - 1] if n[i] == '1' else 0
	print(tot)


t = int(input())

def solve(n):
	val = bin(n)[2:]
	amt = 0
	prev = 0
	for (i, b) in enumerate(val):
		if b == '1':
			added = prev * 2 + 1
			amt += added
			prev = added
		elif b == '0':
			added = prev * 2
			amt += added
			prev = added
	return amt
for _ in range(t):
	n = int(input())
	print(solve(n))


import math

def getN(n):
	return int(math.log2(n))

def func(n):
	nn = getN(n)
	v = 0
	while nn + 1 >= 0:
		nn -= 1
		v += n
		n = n // 2
	return v
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	print(func(n))


import sys
t = int(sys.stdin.readline())
while t:
	n = int(sys.stdin.readline())
	i = 0
	while 2 ** i <= n:
		i += 1
	change = 0
	z = 2 ** (i - 1)
	while z != 0:
		if (n + 1) % z == 0:
			change += (n + 1) // z - 1
		else:
			change += (n + 1) // z
		z = z // 2
	print(change)
	t -= 1


import sys
input = sys.stdin.readline

def cntx(x):
	c = 0
	while x != 0:
		x //= 2
		c += 1
	return (2 ** c - 1, c)
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	while n != 0:
		c = cntx(n)
		ans += c[0]
		n -= 2 ** (c[1] - 1)
	print(ans)


t = int(input())
v = [2 ** (x + 1) - 1 for x in range(60)]
for i in range(t):
	n = int(input())
	s = bin(n)[2:][::-1]
	ans = 0
	for i in range(len(s)):
		if s[i] == '1':
			ans += v[i]
	print(ans)


import math
from sys import stdin, stdout
from heapq import heapify, heappop, heappush
res = [1]
b = 1
i = 1
while i < math.pow(10, 18) + 1:
	res.append(res[-1] * 2 + 1)
	i <<= 1
T = int(stdin.readline())
for i in range(T):
	N = int(stdin.readline())
	ans = 0
	ind = 0
	while N:
		if N & 1:
			ans += res[ind]
		ind += 1
		N >>= 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	E = 0
	for i in range(61):
		E += n // 2 ** i
	print(E)


import math
t = int(input())
for test in range(t):
	n = int(input())
	ans = n
	for i in range(1, 61):
		ans += n // 2 ** i
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	for i in range(60):
		ans += n // 2 ** i
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	d = 1
	ans = 0
	while d <= n:
		ans += n // d
		d *= 2
	print(ans)


def solution():
	a = [1, 2, 1, 3, 1, 2, 1]
	for _ in range(int(input())):
		n = int(input())
		ans = 0
		s = 0
		for i in range(61, -1, -1):
			x = n // 2 ** i
			x -= s
			s += x
			ans += x * (i + 1)
		print(ans)
solution()


for _ in range(int(input())):
	n = int(input())
	ans = 0
	for i in range(len(bin(n))):
		ans += n // pow(2, i)
	print(ans)


def b(n):
	a = 0
	while n != 0:
		if n % 2 == 1:
			a += 1
		n //= 2
	return a
for _ in range(int(input())):
	n = int(input())
	print(2 * n - b(n))


from fractions import Fraction
import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def solve():
	n = int(inp()) + 1
	ans = 0
	for i in range(0, len(bin(n - 1)) - 2):
		lol = n // 2 ** i
		if n % 2 ** i != 0:
			lol += 1
		ans += lol - 1
	print(ans)
testcase(int(inp()))


def binary_search(data, val):
	highIndex = len(data) - 1
	lowIndex = 0
	while highIndex > lowIndex:
		index = (highIndex + lowIndex) // 2
		sub = data[index]
		if data[lowIndex] == val:
			return [lowIndex, lowIndex]
		elif sub == val:
			return [index, index]
		elif data[highIndex] == val:
			return [highIndex, highIndex]
		elif sub > val:
			if highIndex == index:
				return sorted([highIndex, lowIndex])
			highIndex = index
		else:
			if lowIndex == index:
				return sorted([highIndex, lowIndex])
			lowIndex = index
	return sorted([highIndex, lowIndex])
l = [2 ** i for i in range(0, 62)]
t = int(input())
for _ in range(t):
	n = int(input())
	(ma, mi) = binary_search(l, n)
	z = [0] * (ma + 1)
	total = n // l[ma]
	z[-1] = n // l[ma]
	for i in range(ma - 1, 0, -1):
		z[i] = n // l[i] - total
		total += z[i]
	rest = n - sum(z)
	for i in range(len(z)):
		rest += z[i] * (i + 1)
	print(rest)


from math import ceil
for _ in range(int(input())):
	n = int(input())
	s = 0
	for i in range(0, 60):
		if n & 1 << i:
			s = s + (1 << i + 1) - 1
	print(s)


for _ in range(int(input())):
	n = int(input())
	cnt = 1
	ans = 0
	while n != 0:
		d = n // 2
		r = n % 2
		ans += cnt * (d + r)
		n = n // 2
		cnt += 1
	print(ans)


arr = []
p = 2
c = 2
for i in range(60):
	arr.append([p, c])
	p *= 2
	c += 1
arr = arr[::-1]
for _ in range(int(input())):
	n = int(input())
	ans = 0
	t = 0
	for i in arr:
		ans += n // i[0] * i[1] - t
		t += n // i[0]
	ans += n - t
	print(ans)


t = int(input())
while t:
	n = int(input())
	count = n // 2 + n % 2
	l1 = []
	l1.append(0)
	l1.append(2)
	for i in range(2, 64):
		l1.append(l1[-1] * 2 + 1)
	n = n - n % 2
	l2 = []
	while n > 0:
		if n % 2:
			l2.append(1)
		else:
			l2.append(0)
		n = n // 2
	for i in range(len(l2) - 1, -1, -1):
		if l2[i]:
			count = count + l1[i]
	print(count)
	t = t - 1


import sys
import math
input = sys.stdin.readline

def dec2bin(x, ln):
	ans = []
	while x:
		ans.append(x % 2)
		x //= 2
	while len(ans) != ln:
		ans.append(0)
	return list(reversed(ans))

def solve(n):
	ans = 0
	price = 1
	while n:
		ans += (n + 1) // 2 * price
		n //= 2
		price += 1
	return ans
T = int(input())
for t in range(T):
	N = int(input())
	print(solve(N))


from sys import stdin, stdout
from math import ceil

def solve(n):
	c = 0
	while n > 0:
		c += n
		n //= 2
	print(c)
for _ in range(int(input())):
	n = int(stdin.readline())
	solve(n)


MAX = 10 ** 18
f = [None]
SUM = 0
i = 1
while MAX != 0:
	f.append(SUM + i)
	SUM += SUM + i
	i += 1
	MAX //= 2
import sys
for _ in range(int(input())):
	n = int(sys.stdin.readline())
	i = 1
	ans = 0
	while n != 0:
		if n % 2 == 1:
			ans += f[i]
		i += 1
		n //= 2
	print(ans)


from collections import defaultdict as dd
import math
import sys

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return map(int, input().split())

def lm():
	return list(map(int, input().split()))
q = nn()
valdict = {}
valdict[0] = 0
for i in range(1, 100):
	valdict[i] = 2 * valdict[i - 1] + i
for _ in range(q):
	n = nn()
	s = 0
	twopows = []
	p = 0
	while n:
		if n % 2 == 1:
			twopows.append(p)
		p += 1
		n = n >> 1
	for num in twopows:
		s += valdict[num] + num + 1
	print(s)


for _ in range(int(input())):
	n = int(input())
	d2 = 2
	cnt = n
	while d2 <= n:
		cnt += n // d2
		d2 *= 2
	print(cnt)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	o = 0
	for p in range(0, 61):
		o += n // 2 ** p
	print(o)


for _ in range(int(input())):
	n = int(input())
	ans = 0
	cnt = 1
	b = 2
	while b <= n:
		ans += cnt
		ans += cnt * ((n - 2 ** (cnt - 1)) // b)
		cnt += 1
		b *= 2
	if n >= 2 ** (cnt - 1):
		ans += cnt
	print(ans)


def popc(n):
	return bin(n).count('1')
for __ in range(int(input())):
	n = int(input())
	print(2 * n - popc(2 * n))


def f(x):
	return (1 << x + 1) - 1
for n in range(int(input())):
	x = int(input())
	res = 0
	p = 0
	while x > 0:
		if x % 2 == 1:
			res += f(p)
		p += 1
		x //= 2
	print(res)


from sys import stdin
from math import log2, ceil, floor
inp = lambda : stdin.readline().strip()
t = int(inp())
dp = [1] * 62
dp[1] = 2
for i in range(2, 62):
	dp[i] = dp[i - 1] + dp[i - 1] + 1
dp[1] = 3
for i in range(2, 62):
	dp[i] += 2 ** i // 2
for _ in range(t):
	n = int(inp())
	ans = 0
	x = list(bin(n)[2:])
	counter = 0
	for i in x[::-1]:
		if i == '1':
			ans += dp[counter]
		counter += 1
	print(ans)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	count = 1
	flag = True
	a = n
	while True:
		count += 1
		a = a // 2
		if a == 1 or a == 0:
			break
	res = 0
	for i in range(1, count + 1):
		res += i
		nume = n - 2 ** (i - 1)
		res += nume // 2 ** i * i
	print(res)


for _ in range(int(input())):
	n = int(input())
	x = n
	(c, ans) = (0, n // 2 + (n & 1))
	while x:
		x //= 2
		c += 1
	temp = 0
	for i in range(c, 0, -1):
		ans += (n // (1 << i) - temp) * (i + 1)
		temp = n // (1 << i)
	print(ans)


def solve():
	a = int(input())
	resposta = 0
	for i in range(60):
		if a & 1 << i:
			resposta += (1 << i + 1) - 1
	print(resposta)
test = int(input())
while test > 0:
	solve()
	test -= 1


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	p = bin(n)
	s = len(p) - 2
	ans = 0
	for i in range(s):
		ans += n // 2 ** i
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = []
	i = 1
	while i <= n:
		arr.append(n // i)
		i *= 2
	for i in range(len(arr) - 1):
		arr[i] -= arr[i + 1]
	ans = 0
	t = 1
	for i in range(len(arr)):
		ans += arr[i] * t
		t += 1
	print(ans)


for t in range(int(input())):
	n = int(input())
	bin_n = bin(n)[2:]
	ans = 0
	l = len(bin_n)
	i = 1
	ans = n - 1
	while i < l:
		ans += n // 2 ** i
		i += 1
	print(ans + 1)


import sys
input = sys.stdin.buffer.readline
from math import log, ceil

def I():
	return list(map(int, input().split()))

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a

def precalc():
	arr = [0] * 61
	curr = 1
	for i in range(61):
		arr[i] = curr
		curr *= 2
	return arr
powers = precalc()
for __ in range(int(input())):
	m = int(input())
	n = ceil(log(m, 2)) + 1
	s = 0
	for i in range(n):
		pow2 = powers[i]
		s += m // pow2
	print(s)


for T in range(int(input())):
	n = int(input())
	i = 1
	res = 0
	while n > 0:
		if n & 1:
			res += 2 ** i - 1
		n = n >> 1
		i += 1
	print(res)


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	n = int(input())
	i = 0
	ans = 0
	while True:
		j = 2 ** i
		cnt = (n + 1) // j + int((n + 1) % j != 0)
		if cnt == 1:
			break
		ans += cnt - 1
		i += 1
	print(ans)


for _ in range(int(input())):
	k = int(input())
	r = 0
	i = x = 1
	while x:
		x = -(-(1 + k - int(2 ** (i - 1))) // 2 ** i)
		r += x * i
		if x == 0:
			break
		i += 1
	print(r)


from bisect import bisect_left as lower_bound, bisect_right as upper_bound
from sys import stdin, stdout
from collections import defaultdict

def solve(arr, n):
	pass

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		cnt = 0
		for i in range(65):
			r = 1 << i
			cnt += n // r
		print(cnt)
main()


t = int(input())
for tc in range(t):
	n = int(input())
	ans = 0
	div = 1
	while div <= n:
		ans += n // div
		div *= 2
	print(ans)


import math as mt
import collections as cc
import sys
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n,) = I()
	ans = 0
	for i in range(64):
		if n & 1 << i:
			ans += (1 << i + 1) - 1
	print(ans)


t = int(input())
while t > 0:
	n = int(input())
	res = 0
	while n > 0:
		res += n
		n //= 2
	print(int(res))
	t -= 1


def rec(x):
	if x == 0:
		return 0
	if x == 1:
		return 1
	return rec(x - (x & -x)) + (x & -x) * 2 - 1
T = int(input())
for _ in range(T):
	n = int(input())
	print(rec(n))


n = int(input())
for i in range(n):
	x = int(input())
	s = bin(x)[2:][::-1]
	rez = 0
	for (num, val) in enumerate(s, start=1):
		if val == '1':
			rez += 2 ** num - 1
	print(rez)


lst = [0] * 80
lst[0] = 1
for i in range(1, 80):
	lst[i] = lst[i - 1] * 2 + 1
for t in range(int(input())):
	n = int(input())
	ans = 0
	i = 0
	while n:
		if n % 2 == 1:
			ans += lst[i]
		i += 1
		n //= 2
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	ans = 0
	i = 0
	for i in range(64):
		ans += n // 2 ** i
		if 2 ** i > n:
			break
	print(ans)