#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 argc, char const *argv[]) {
  int t;
  scanf("%d", &t);
  int n, c, m;
  for (int i_t = 0; i_t < t; i_t++) {
    scanf("%d %d %d", &n, &c, &m);
    int total = n / c;
    int tickets = total;
    while (tickets >= m) {
      total += tickets / m;
      tickets = tickets / m + tickets % m;
    }
    printf("%d\n", total);
  }
  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)
lea    0xec9(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d9 <main+0xb9>
lea    0xe9e(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x18(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jl     11bc <main+0x9c>
mov    -0x2c(%rbp),%eax
cltd
idivl  -0x20(%rbp)
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    -0x30(%rbp),%eax
add    %edx,%eax
mov    %eax,-0x2c(%rbp)
jmp    1185 <main+0x65>
mov    -0x28(%rbp),%esi
lea    0xe43(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114f <main+0x2f>
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(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 i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
store i32 0, i32* %10
br label %14
14: ; preds = %44, %2
%15 = load i32, i32* %10
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %47
18: ; preds = %14
%19 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %7, i32* %8, i32* %9)
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = sdiv i32 %20, %21
store i32 %22, i32* %11
%23 = load i32, i32* %11
store i32 %23, i32* %12
br label %24
24: ; preds = %28, %18
%25 = load i32, i32* %12
%26 = load i32, i32* %9
%27 = icmp sge i32 %25, %26
br i1 %27, label %28, label %41
28: ; preds = %24
%29 = load i32, i32* %12
%30 = load i32, i32* %9
%31 = sdiv i32 %29, %30
%32 = load i32, i32* %11
%33 = add nsw i32 %32, %31
store i32 %33, i32* %11
%34 = load i32, i32* %12
%35 = load i32, i32* %9
%36 = sdiv i32 %34, %35
%37 = load i32, i32* %12
%38 = load i32, i32* %9
%39 = srem i32 %37, %38
%40 = add nsw i32 %36, %39
store i32 %40, i32* %12
br label %24
41: ; preds = %24
%42 = load i32, i32* %11
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %41
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
br label %14
47: ; preds = %14
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(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %31, %2
ret i32 0
15: ; preds = %2, %31
%16 = phi i32 [ %34, %31 ], [ 0, %2 ]
%17 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5, i32* %6)
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = sdiv i32 %18, %19
%21 = load i32, i32* %6
%22 = icmp slt i32 %20, %21
br i1 %22, label %31, label %23
23: ; preds = %15, %23
%24 = phi i32 [ %29, %23 ], [ %20, %15 ]
%25 = phi i32 [ %27, %23 ], [ %20, %15 ]
%26 = sdiv i32 %24, %21
%27 = add nsw i32 %26, %25
%28 = srem i32 %24, %21
%29 = add nsw i32 %28, %26
%30 = icmp slt i32 %29, %21
br i1 %30, label %31, label %23
31: ; preds = %23, %15
%32 = phi i32 [ %20, %15 ], [ %27, %23 ]
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = add nuw nsw i32 %16, 1
%35 = load i32, i32* %3
%36 = icmp slt i32 %34, %35
br i1 %36, label %15, label %14
}