#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  short t, temp;
  int num, menus;
  scanf("%hd", &t);
  while (t--) {
    scanf("%d", &num);
    temp = 2048;
    menus = 0;
    while (num > 0) {
      while (num >= temp) {
        num -= temp;
        menus++;
      }
      temp /= 2;
      if (temp == 0)
        temp = 1;
    }
    printf("%d\n", menus);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x6(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x6(%rbp),%ax
mov    %ax,%cx
add    $0xffff,%cx
mov    %cx,-0x6(%rbp)
cmp    $0x0,%ax
je     11ed <main+0xcd>
lea    0xea3(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movw   $0x800,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11d9 <main+0xb9>
jmp    1188 <main+0x68>
mov    -0xc(%rbp),%eax
movswl -0x8(%rbp),%ecx
cmp    %ecx,%eax
jl     11b1 <main+0x91>
movswl -0x8(%rbp),%ecx
mov    -0xc(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1188 <main+0x68>
movswl -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %ax,-0x8(%rbp)
movswl -0x8(%rbp),%eax
cmp    $0x0,%eax
jne    11d4 <main+0xb4>
movw   $0x1,-0x8(%rbp)
jmp    1179 <main+0x59>
mov    -0x10(%rbp),%esi
lea    0xe24(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xecd(%rip),%rdi
lea    0xa(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subw   $0x1,0xa(%rsp)
jae    1156 <main+0x36>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xea7(%rip),%r14
lea    0xc(%rsp),%r15
mov    $0x1,%ebx
lea    0xe99(%rip),%r12
jmp    1182 <main+0x62>
mov    %r12,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
subw   $0x1,0xa(%rsp)
jb     1147 <main+0x27>
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    1170 <main+0x50>
mov    $0x800,%ecx
xor    %ebp,%ebp
jmp    11c5 <main+0xa5>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
test   %dx,%dx
cmove  %ebx,%edx
mov    %edx,%ecx
test   %eax,%eax
jle    1170 <main+0x50>
cmp    %ecx,%eax
jl     11b0 <main+0x90>
nopl   0x0(%rax)
sub    %ecx,%eax
add    $0x1,%ebp
cmp    %ecx,%eax
jge    11d0 <main+0xb0>
mov    %eax,0xc(%rsp)
jmp    11b0 <main+0x90>

LLVM IR (-O0):
@.str = [4 x i8] c"%hd\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i16
%3 = alloca i16
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16* %2)
br label %7
7: ; preds = %39, %0
%8 = load i16, i16* %2
%9 = add i16 %8, -1
store i16 %9, i16* %2
%10 = icmp ne i16 %8, 0
br i1 %10, label %11, label %42
11: ; preds = %7
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
store i16 2048, i16* %3
store i32 0, i32* %5
br label %13
13: ; preds = %38, %11
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %39
16: ; preds = %13
br label %17
17: ; preds = %22, %16
%18 = load i32, i32* %4
%19 = load i16, i16* %3
%20 = sext i16 %19 to i32
%21 = icmp sge i32 %18, %20
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = load i16, i16* %3
%24 = sext i16 %23 to i32
%25 = load i32, i32* %4
%26 = sub nsw i32 %25, %24
store i32 %26, i32* %4
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %17
29: ; preds = %17
%30 = load i16, i16* %3
%31 = sext i16 %30 to i32
%32 = sdiv i32 %31, 2
%33 = trunc i32 %32 to i16
store i16 %33, i16* %3
%34 = load i16, i16* %3
%35 = sext i16 %34 to i32
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %29
store i16 1, i16* %3
br label %38
38: ; preds = %37, %29
br label %13
39: ; preds = %13
%40 = load i32, i32* %5
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %40)
br label %7
42: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%hd\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i16
%2 = alloca i32
%3 = bitcast i16* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i16* %1)
%6 = load i16, i16* %1
%7 = add i16 %6, -1
store i16 %7, i16* %1
%8 = icmp eq i16 %6, 0
br i1 %8, label %39, label %9
9: ; preds = %0, %33
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %33
13: ; preds = %9, %25
%14 = phi i32 [ %27, %25 ], [ 0, %9 ]
%15 = phi i32 [ %31, %25 ], [ 2048, %9 ]
%16 = phi i32 [ %26, %25 ], [ %11, %9 ]
%17 = icmp slt i32 %16, %15
br i1 %17, label %25, label %18
18: ; preds = %13, %18
%19 = phi i32 [ %22, %18 ], [ %14, %13 ]
%20 = phi i32 [ %21, %18 ], [ %16, %13 ]
%21 = sub nsw i32 %20, %15
%22 = add nsw i32 %19, 1
%23 = icmp slt i32 %21, %15
br i1 %23, label %24, label %18
24: ; preds = %18
store i32 %21, i32* %2
br label %25
25: ; preds = %24, %13
%26 = phi i32 [ %21, %24 ], [ %16, %13 ]
%27 = phi i32 [ %22, %24 ], [ %14, %13 ]
%28 = sdiv i32 %15, 2
%29 = and i32 %28, 65535
%30 = icmp eq i32 %29, 0
%31 = select i1 %30, i32 1, i32 %28
%32 = icmp sgt i32 %26, 0
br i1 %32, label %13, label %33
33: ; preds = %25, %9
%34 = phi i32 [ 0, %9 ], [ %27, %25 ]
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i16, i16* %1
%37 = add i16 %36, -1
store i16 %37, i16* %1
%38 = icmp eq i16 %36, 0
br i1 %38, label %39, label %9
39: ; preds = %33, %0
ret i32 0
}