import java.util.*;

class Main{
	public static void main (String[] args){
		Scanner in = new Scanner(System.in);
		long q, x, res, two; 
		q = in.nextInt();
		for(long i = 0; i < q; ++ i){
			x = in.nextLong();
			res = 0;
			two = 1; // two = 2^0
			while(x > 0){
				if(x % 2 == 0) // check if the last bit is equal to zero
					res += two;
				x >>= 1;	// moving to the next bit
				two <<= 1; // same as two *= 2
			}
			System.out.println(res);
		}
	}
}