'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
def compute(n):
	if n==0:
		return 0
	k = (n+1)/2
	return k*k + compute(n/2)
t=input()
while t>0:
	x=input()
	print compute(x)
	t-=1