#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 *, ...);
int main() {
  int t, i, j, k, c, num, temp, m;
  scanf("%d", &t);
  while (t--) {
    c = 1;
    scanf("%d %d", &num, &k);
    while (num > 0) {
      temp = num - k;
      if (temp > 0) {
        m = (temp - (num + 1) / 2);
        printf("diff=%d   ", m);
        c += m;
        c++;
      }
      num = num - k;
    }
    printf("%d\n", c);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xecd(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11f0 <main+0xd0>
movl   $0x1,-0x18(%rbp)
lea    0xe9d(%rip),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    11dc <main+0xbc>
mov    -0x1c(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    11ce <main+0xae>
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1172 <main+0x52>
mov    -0x18(%rbp),%esi
lea    0xe2b(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
xor    %eax,%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
lea    0xece(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0x14(%rsp)
jae    1159 <main+0x39>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xe9c(%rip),%rbx
lea    0xea0(%rip),%r13
jmp    1196 <main+0x76>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14d,0xc(%rsp)
mov    %r13,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
subl   $0x1,0x14(%rsp)
jb     1148 <main+0x28>
lea    0xe63(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
mov    $0x1,%ebp
test   %eax,%eax
jle    1185 <main+0x65>
mov    0x10(%rsp),%ecx
nopl   0x0(%rax,%rax,1)
mov    %eax,%r14d
sub    %ecx,%r14d
jle    1180 <main+0x60>
add    $0x1,%eax
shr    %eax
sub    %eax,%r14d
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
add    %r14d,%ebp
add    $0x1,%ebp
mov    0xc(%rsp),%eax
mov    0x10(%rsp),%ecx
sub    %ecx,%eax
mov    %eax,0xc(%rsp)
jg     11c0 <main+0xa0>
jmp    1185 <main+0x65>

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

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