import java.io.FileReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Scanner;


public class Legion 
{
	public static void main(String[] args) throws Exception
	{
		new Legion().solve();
	}

	Scanner in = null;
	PrintWriter out = null;
	HashMap<Long, Long> map = null;
	
	final int MAX_CACHE = 1000000;
	long cache[] = null;
	
	private void solve() throws Exception
	{
		in = new Scanner(new FileReader("legion.in"));
		//out = new PrintWriter("legion.out");
		out = new PrintWriter(System.out);
		
		map = new HashMap<Long, Long>();
		cache = new long[MAX_CACHE];
		cache[1] = 0;
		cache[2] = 0;
		cache[3] = 1;
		
		for (int i = 4; i < MAX_CACHE; i++)
		{
			cache[i] = cache[i/2] + cache[i - i/2]; 
		}
		
		int testn = in.nextInt();
		
		for (int testi = 0; testi < testn; testi++)
		{
			long n = in.nextLong();
			if (n < 1L || n > 1000000000000000000L)
				throw new Exception("Assert!!!");
			out.println(f(n));
		}
		
		out.close();
	}

	private long f(long n) 
	{
		if (n < MAX_CACHE)
			return cache[(int)n];
		
		Long key = Long.valueOf(n);
		Long value = map.get(key);
		if (value != null)
			return value.longValue(); 
		
		value = Long.valueOf(f(n/2) + f(n - n/2));
		map.put(key, value);
		
		return value.longValue(); 
	}
}
