import std.stdio;
import std.stdio;
import std.algorithm;
import std.range;
import std.functional;
import std.conv;
import std.string;
import std.math;
import core.bitop;

ulong diff(ulong a, ulong b) {
	ulong res = 0;
	foreach (bit; 0 .. 64) {
		if ((a & (1UL << bit)) != (b & (1UL << bit))) {
			res++;
		}
	}
	return res;
}

ulong calc(ulong a) {
	if ((a & (a - 1)) == 0) {
		return a | (a - 1);
	}
	else {
		ulong highestBit = 1UL << bsr(a);
		return calc(a - highestBit) + calc(highestBit);
	}
}

void main() {
	// ulong res = 0;
	// foreach (i; 0 .. 1000) {
	// 	res += diff(i, i + 1);
	// 	write("f(", (i + 1).to!string.padLeft(' ', 10), ") = ", res.to!string(2).padLeft('0', 10));
	// 	writeln("; ", calc(i + 1).to!string(2).padLeft('0', 10));
	// }
	int tt = readln().chomp.to!int;
	outer: foreach (t; 0 .. tt) {
		ulong n = readln().chomp.to!ulong;
		// writeln(n.to!string(2).padLeft('0', 64));
		writeln(calc(n));
	}
}
