#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 *, long long);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int t, i;
  scanf("%d", &t);
  long long int arr[t], n, T, f, k;
  for (i = 0; i < t; i++) {
    fflush(0);
    scanf("%lld%lld%lld%lld", &n, &k, &T, &f);
    arr[i] = (f - n) / (k - 1) + f;
  }
  for (i = 0; i < t; i++)
    printf("%lld\n", arr[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %eax,%eax
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e6 <main+0xb6>
xor    %edi,%edi
call   1040 <fflush@plt>
lea    0xe6a(%rip),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x30(%rbp),%rcx
lea    -0x38(%rbp),%r8
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x38(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    -0x40(%rbp),%rcx
sub    $0x1,%rcx
cqto
idiv   %rcx
mov    %rax,%rdx
mov    -0x48(%rbp),%rax
add    -0x38(%rbp),%rdx
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117f <main+0x4f>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121f <main+0xef>
mov    -0x48(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe08(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ed <main+0xbd>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xeb8(%rip),%rdi
xor    %r15d,%r15d
lea    -0x2c(%rbp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %rsp,%r12
mov    -0x2c(%rbp),%eax
mov    %rsp,%r14
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    1229 <main+0xf9>
mov    %r12,-0x38(%rbp)
lea    -0x40(%rbp),%r12
lea    -0x58(%rbp),%r13
lea    -0x48(%rbp),%rbx
jmp    11a9 <main+0x79>
nopl   (%rax)
cqto
idiv   %rsi
add    %rcx,%rax
mov    %rax,(%r14,%r15,8)
add    $0x1,%r15
movslq -0x2c(%rbp),%rax
cmp    %rax,%r15
jge    11f0 <main+0xc0>
xor    %edi,%edi
call   1040 <fflush@plt>
lea    0xe4c(%rip),%rdi
lea    -0x50(%rbp),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <scanf@plt>
mov    -0x48(%rbp),%rcx
mov    %rcx,%rax
sub    -0x50(%rbp),%rax
mov    -0x40(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
mov    %rax,%rdx
or     %rsi,%rdx
shr    $0x20,%rdx
jne    1190 <main+0x60>
xor    %edx,%edx
div    %esi
jmp    1195 <main+0x65>
test   %eax,%eax
mov    -0x38(%rbp),%r12
jle    1229 <main+0xf9>
xor    %ebx,%ebx
lea    0xe13(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rsi
mov    %r15,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     1210 <main+0xe0>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%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 = [17 x i8] c"%lld%lld%lld%lld\00"
@.str.2 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i64, i64 %12
store i64 %12, i64* %5
store i32 0, i32* %3
br label %15
15: ; preds = %33, %0
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %36
19: ; preds = %15
%20 = call i32 @fflush(i32 0)
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i64* %6, i64* %9, i64* %7, i64* %8)
%22 = load i64, i64* %8
%23 = load i64, i64* %6
%24 = sub nsw i64 %22, %23
%25 = load i64, i64* %9
%26 = sub nsw i64 %25, 1
%27 = sdiv i64 %24, %26
%28 = load i64, i64* %8
%29 = add nsw i64 %27, %28
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i64, i64* %14, i64 %31
store i64 %29, i64* %32
br label %33
33: ; preds = %19
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %15
36: ; preds = %15
store i32 0, i32* %3
br label %37
37: ; preds = %47, %36
%38 = load i32, i32* %3
%39 = load i32, i32* %2
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %50
41: ; preds = %37
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i64, i64* %14, i64 %43
%45 = load i64, i64* %44
%46 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %45)
br label %47
47: ; preds = %41
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 1
store i32 %49, i32* %3
br label %37
50: ; preds = %37
store i32 0, i32* %1
%51 = load i8*, i8** %4
%52 = load i32, i32* %1
ret i32 %52
}

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