#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 test_cases, n, c, m, i, chocolates, wrappers, extra_wrappers;
  scanf("%d", &test_cases);
  for (i = 0; i < test_cases; i++) {
    scanf("%d %d %d", &n, &c, &m);
    chocolates = n / c;
    wrappers = chocolates;
    extra_wrappers = wrappers % m;
    while (wrappers >= m) {
      chocolates += wrappers / m;
      wrappers = extra_wrappers + wrappers / m;
      extra_wrappers = wrappers % m;
    }
    printf("%d\n", chocolates);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed0(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e4 <main+0xc4>
lea    0xea5(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x24(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11c7 <main+0xa7>
mov    -0x20(%rbp),%eax
cltd
idivl  -0x14(%rbp)
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x24(%rbp)
jmp    1188 <main+0x68>
mov    -0x1c(%rbp),%esi
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1148 <main+0x28>
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    0xed1(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11bf <main+0x9f>
lea    0xeb1(%rip),%r14
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
lea    0xea4(%rip),%rbx
xor    %ebp,%ebp
jmp    1183 <main+0x63>
nopl   0x0(%rax)
mov    %edx,%esi
mov    %rbx,%rdi
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    0x8(%rsp),%ebp
jge    11bf <main+0x9f>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x14(%rsp),%eax
cltd
idivl  0x10(%rsp)
mov    %eax,%edx
mov    0xc(%rsp),%ecx
cmp    %ecx,%eax
jl     1170 <main+0x50>
mov    %edx,%esi
nopl   0x0(%rax,%rax,1)
mov    %edx,%eax
cltd
idiv   %ecx
add    %eax,%esi
add    %eax,%edx
cmp    %ecx,%edx
jge    11b0 <main+0x90>
jmp    1172 <main+0x52>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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