#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  int n, decimal, hexadecimal, binary1, binary2;
  char number[5];
  fflush(stdin);
  scanf("%d", &n);
  if (n <= 0 || n > 1000)
    return 1;
  while (n--) {
    scanf("%s", number);
    sscanf(number, "%d", &decimal);
    sscanf(number, "%x", &hexadecimal);
    binary1 = binary2 = 0;
    while (decimal) {
      if (decimal & 1)
        binary1++;
      decimal >>= 1;
    }
    while (hexadecimal) {
      if (hexadecimal & 1)
        binary2++;
      hexadecimal >>= 1;
    }
    printf("%d %d\n", binary1, binary2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
lea    0xe95(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
cmpl   $0x0,-0x14(%rbp)
jle    118d <main+0x4d>
cmpl   $0x3e8,-0x14(%rbp)
jle    1199 <main+0x59>
movl   $0x1,-0x4(%rbp)
jmp    127d <main+0x13d>
jmp    119e <main+0x5e>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1276 <main+0x136>
lea    -0x29(%rbp),%rsi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x29(%rbp),%rdi
lea    0xe31(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <sscanf@plt>
lea    -0x29(%rbp),%rdi
lea    0xe23(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <sscanf@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     122a <main+0xea>
mov    -0x18(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     121c <main+0xdc>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11fa <main+0xba>
jmp    122f <main+0xef>
cmpl   $0x0,-0x1c(%rbp)
je     125f <main+0x11f>
mov    -0x1c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1251 <main+0x111>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    122f <main+0xef>
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xd9d(%rip),%rdi
call   1030 <printf@plt>
jmp    119e <main+0x5e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
lea    0xe9d(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x4(%rsp),%ecx
lea    -0x3e9(%rcx),%edx
mov    $0x1,%eax
cmp    $0xfffffc18,%edx
jb     124c <main+0x10c>
add    $0xffffffff,%ecx
mov    %ecx,0x4(%rsp)
lea    0x13(%rsp),%rbx
lea    0xc(%rsp),%r12
lea    0xe64(%rip),%r13
lea    0x8(%rsp),%rbp
lea    0xe5b(%rip),%r14
jmp    11c6 <main+0x86>
mov    %r14,%rdi
mov    %r15d,%edx
call   1030 <printf@plt>
subl   $0x1,0x4(%rsp)
jb     124a <main+0x10a>
xor    %r15d,%r15d
lea    0xe33(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %rbx,%rdi
lea    0xe1c(%rip),%rsi
mov    %r12,%rdx
call   1050 <sscanf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1050 <sscanf@plt>
mov    0xc(%rsp),%eax
mov    $0x0,%esi
test   %eax,%eax
je     1224 <main+0xe4>
xor    %esi,%esi
nopl   0x0(%rax)
mov    %eax,%ecx
mov    %eax,%edx
and    $0x1,%edx
add    %edx,%esi
sar    %eax
cmp    $0x1,%ecx
ja     1210 <main+0xd0>
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%eax
test   %eax,%eax
je     11b0 <main+0x70>
xor    %r15d,%r15d
nop
mov    %eax,%ecx
mov    %eax,%edx
and    $0x1,%edx
add    %edx,%r15d
sar    %eax
cmp    $0x1,%ecx
ja     1230 <main+0xf0>
mov    %eax,0x8(%rsp)
jmp    11b0 <main+0x70>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [7 x i8] c"%d %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [5 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @stdin
%13 = call i32 @fflush(i32 %12)
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%15 = load i32, i32* %6
%16 = icmp sle i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %2
%18 = load i32, i32* %6
%19 = icmp sgt i32 %18, 1000
br i1 %19, label %20, label %21
20: ; preds = %17, %2
store i32 1, i32* %3
br label %65
21: ; preds = %17
br label %22
22: ; preds = %60, %21
%23 = load i32, i32* %6
%24 = add nsw i32 %23, -1
store i32 %24, i32* %6
%25 = icmp ne i32 %23, 0
br i1 %25, label %26, label %64
26: ; preds = %22
%27 = getelementptr inbounds [5 x i8], [5 x i8]* %11, i64 0, i64 0
%28 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds [5 x i8], [5 x i8]* %11, i64 0, i64 0
%30 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%31 = getelementptr inbounds [5 x i8], [5 x i8]* %11, i64 0, i64 0
%32 = call i32 @sscanf(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
store i32 0, i32* %10
store i32 0, i32* %9
br label %33
33: ; preds = %43, %26
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %46
36: ; preds = %33
%37 = load i32, i32* %7
%38 = and i32 %37, 1
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %43
43: ; preds = %40, %36
%44 = load i32, i32* %7
%45 = ashr i32 %44, 1
store i32 %45, i32* %7
br label %33
46: ; preds = %33
br label %47
47: ; preds = %57, %46
%48 = load i32, i32* %8
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %60
50: ; preds = %47
%51 = load i32, i32* %8
%52 = and i32 %51, 1
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
br label %57
57: ; preds = %54, %50
%58 = load i32, i32* %8
%59 = ashr i32 %58, 1
store i32 %59, i32* %8
br label %47
60: ; preds = %47
%61 = load i32, i32* %9
%62 = load i32, i32* %10
%63 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %61, i32 %62)
br label %22
64: ; preds = %22
store i32 0, i32* %3
br label %65
65: ; preds = %64, %20
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [7 x i8] c"%d %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [5 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = tail call i32 @fflush(i32 %11)
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%14 = load i32, i32* %3
%15 = add i32 %14, -1001
%16 = icmp ult i32 %15, -1000
br i1 %16, label %51, label %17
17: ; preds = %2
%18 = add nsw i32 %14, -1
store i32 %18, i32* %3
br label %19
19: ; preds = %17, %45
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%21 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%22 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %19, %25
%26 = phi i32 [ %29, %25 ], [ 0, %19 ]
%27 = phi i32 [ %30, %25 ], [ %23, %19 ]
%28 = and i32 %27, 1
%29 = add nuw nsw i32 %26, %28
%30 = ashr i32 %27, 1
%31 = icmp ult i32 %27, 2
br i1 %31, label %32, label %25
32: ; preds = %25
store i32 %30, i32* %4
br label %33
33: ; preds = %32, %19
%34 = phi i32 [ %29, %32 ], [ 0, %19 ]
%35 = load i32, i32* %5
%36 = icmp eq i32 %35, 0
br i1 %36, label %45, label %37
37: ; preds = %33, %37
%38 = phi i32 [ %41, %37 ], [ 0, %33 ]
%39 = phi i32 [ %42, %37 ], [ %35, %33 ]
%40 = and i32 %39, 1
%41 = add nuw nsw i32 %38, %40
%42 = ashr i32 %39, 1
%43 = icmp ult i32 %39, 2
br i1 %43, label %44, label %37
44: ; preds = %37
store i32 %42, i32* %5
br label %45
45: ; preds = %44, %33
%46 = phi i32 [ %41, %44 ], [ 0, %33 ]
%47 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 %46)
%48 = load i32, i32* %3
%49 = add nsw i32 %48, -1
store i32 %49, i32* %3
%50 = icmp eq i32 %48, 0
br i1 %50, label %51, label %19
51: ; preds = %45, %2
%52 = phi i32 [ 1, %2 ], [ 0, %45 ]
ret i32 %52
}