#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 *, unsigned int);
int /*<<< orphan*/ scanf(char *, unsigned int *);
int main() {
  unsigned T, N, i, res;
  scanf("%u", &T);
  for (i = 0; i < T; i++) {
    scanf("%u", &N);
    res = 0;
    while (N > 0) {
      if (N > 2048) {
        res += N / 2048;
        N = N % 2048;
        continue;
      }
      res += N & 0x01;
      N = N >> 1;
    }
    printf("%u\n", res);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    11d3 <main+0xb3>
lea    0xea7(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jbe    11b6 <main+0x96>
cmpl   $0x800,-0xc(%rbp)
jbe    119c <main+0x7c>
mov    -0xc(%rbp),%eax
shr    $0xb,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
and    $0x7ff,%eax
mov    %eax,-0xc(%rbp)
jmp    1169 <main+0x49>
mov    -0xc(%rbp),%eax
and    $0x1,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1169 <main+0x49>
mov    -0x14(%rbp),%esi
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1146 <main+0x26>
xor    %eax,%eax
add    $0x20,%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    0xc(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
je     11bf <main+0x9f>
xor    %ebp,%ebp
lea    0xeb3(%rip),%r14
lea    0x8(%rsp),%r15
lea    0xeaa(%rip),%r12
jmp    1171 <main+0x51>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jae    11bf <main+0x9f>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
mov    0x8(%rsp),%eax
mov    $0x0,%esi
test   %eax,%eax
je     1160 <main+0x40>
xor    %esi,%esi
nopl   0x0(%rax,%rax,1)
mov    %eax,%ecx
and    $0x1,%ecx
mov    %eax,%edx
shr    %edx
mov    %eax,%edi
shr    $0xb,%edi
mov    %eax,%ebx
and    $0x7ff,%ebx
cmp    $0x801,%eax
mov    %ebx,%eax
cmovb  %edx,%eax
cmovb  %ecx,%edi
add    %edi,%esi
test   %eax,%eax
jne    1190 <main+0x70>
mov    %eax,0x8(%rsp)
jmp    1160 <main+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
@.str.1 = [4 x i8] c"%u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %4
br label %7
7: ; preds = %36, %0
%8 = load i32, i32* %4
%9 = load i32, i32* %2
%10 = icmp ult i32 %8, %9
br i1 %10, label %11, label %39
11: ; preds = %7
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 0, i32* %5
br label %13
13: ; preds = %26, %19, %11
%14 = load i32, i32* %3
%15 = icmp ugt i32 %14, 0
br i1 %15, label %16, label %33
16: ; preds = %13
%17 = load i32, i32* %3
%18 = icmp ugt i32 %17, 2048
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i32, i32* %3
%21 = udiv i32 %20, 2048
%22 = load i32, i32* %5
%23 = add i32 %22, %21
store i32 %23, i32* %5
%24 = load i32, i32* %3
%25 = urem i32 %24, 2048
store i32 %25, i32* %3
br label %13
26: ; preds = %16
%27 = load i32, i32* %3
%28 = and i32 %27, 1
%29 = load i32, i32* %5
%30 = add i32 %29, %28
store i32 %30, i32* %5
%31 = load i32, i32* %3
%32 = lshr i32 %31, 1
store i32 %32, i32* %3
br label %13
33: ; preds = %13
%34 = load i32, i32* %5
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %33
%37 = load i32, i32* %4
%38 = add i32 %37, 1
store i32 %38, i32* %4
br label %7
39: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
@.str.1 = [4 x i8] c"%u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, 0
br i1 %7, label %32, label %8
8: ; preds = %0, %26
%9 = phi i32 [ %29, %26 ], [ 0, %0 ]
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %26, label %13
13: ; preds = %8, %13
%14 = phi i32 [ %23, %13 ], [ 0, %8 ]
%15 = phi i32 [ %21, %13 ], [ %11, %8 ]
%16 = icmp ugt i32 %15, 2048
%17 = and i32 %15, 1
%18 = lshr i32 %15, 1
%19 = lshr i32 %15, 11
%20 = and i32 %15, 2047
%21 = select i1 %16, i32 %20, i32 %18
%22 = select i1 %16, i32 %19, i32 %17
%23 = add i32 %14, %22
%24 = icmp eq i32 %21, 0
br i1 %24, label %25, label %13
25: ; preds = %13
store i32 %21, i32* %2
br label %26
26: ; preds = %25, %8
%27 = phi i32 [ 0, %8 ], [ %23, %25 ]
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = add nuw i32 %9, 1
%30 = load i32, i32* %1
%31 = icmp ult i32 %29, %30
br i1 %31, label %8, label %32
32: ; preds = %26, %0
ret i32 0
}