memo={} def f(n): if n<=1: return n if n in memo: return memo[n] if n%2==0: res=f(n//2) memo[n]=res return res else: res=1+min(f(n//2),f(n//2+1)) memo[n]=res return res memo2={} def calc(n): if n==1: return 0,1,0,0 if n in memo2: return memo2[n] if n%4==0: res,a,b,c=calc(n//4) res2=4*res+4*a+3*b+c a2=2*a+b+c b2=a+2*b+c c2=a+b+2*c memo2[n]=(res2,a2,b2,c2) return res2,a2,b2,c2 res,a,b,c=calc(n-1) p=f(n-1) q=f(n) res+=p if pq: c+=1 memo2[n]=res,a,b,c return res,a,b,c for _ in range(int(input())): n=int(input()) print(calc(n+1)[0])