#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 nextNumberMultipleOf3(unsigned long);
int nextNumberMultipleOf5(unsigned long);
int /*<<< orphan*/ printf(char *, unsigned long);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int t;
  unsigned long num, sum, i;
  scanf("%d", &t);
  while (t-- > 0) {
    sum = 0;
    scanf("%d", &num);
    for (i = 3; i < num;) {
      sum += i;
      int next3 = nextNumberMultipleOf3(i);
      int next5 = nextNumberMultipleOf5(i);
      if (next3 < next5) {
        i = next3;
      } else {
        i = next5;
      }
    }
    printf("%lu\n", sum);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
jle    1204 <main+0xc4>
movq   $0x0,-0x18(%rbp)
lea    0xe7c(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movq   $0x3,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11ef <main+0xaf>
mov    -0x20(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <nextNumberMultipleOf3@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <nextNumberMultipleOf5@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11e2 <main+0xa2>
movslq -0x24(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11ea <main+0xaa>
movslq -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1197 <main+0x57>
mov    -0x18(%rbp),%rsi
lea    0xe09(%rip),%rdi
call   1030 <printf@plt>
jmp    1161 <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    0xeab(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
test   %eax,%eax
jle    11f6 <main+0xb6>
lea    0xe85(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xe7c(%rip),%r12
jmp    11ad <main+0x6d>
nopl   0x0(%rax)
xor    %r13d,%r13d
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <printf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
test   %eax,%eax
jle    11f6 <main+0xb6>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpq   $0x4,0x10(%rsp)
jb     1190 <main+0x50>
mov    $0x3,%ebx
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
add    %rbx,%r13
mov    %rbx,%rdi
call   1050 <nextNumberMultipleOf3@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <nextNumberMultipleOf5@plt>
cmp    %eax,%ebp
cmovl  %ebp,%eax
movslq %eax,%rbx
cmp    %rbx,0x10(%rsp)
ja     11d0 <main+0x90>
jmp    1193 <main+0x53>
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 = [5 x i8] c"%lu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %9
9: ; preds = %37, %0
%10 = load i32, i32* %2
%11 = add nsw i32 %10, -1
store i32 %11, i32* %2
%12 = icmp sgt i32 %10, 0
br i1 %12, label %13, label %40
13: ; preds = %9
store i64 0, i64* %4
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64* %3)
store i64 3, i64* %5
br label %15
15: ; preds = %36, %13
%16 = load i64, i64* %5
%17 = load i64, i64* %3
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %37
19: ; preds = %15
%20 = load i64, i64* %5
%21 = load i64, i64* %4
%22 = add i64 %21, %20
store i64 %22, i64* %4
%23 = load i64, i64* %5
%24 = call i32 @nextNumberMultipleOf3(i64 %23)
store i32 %24, i32* %6
%25 = load i64, i64* %5
%26 = call i32 @nextNumberMultipleOf5(i64 %25)
store i32 %26, i32* %7
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %19
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
store i64 %32, i64* %5
br label %36
33: ; preds = %19
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
store i64 %35, i64* %5
br label %36
36: ; preds = %33, %30
br label %15
37: ; preds = %15
%38 = load i64, i64* %4
%39 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %38)
br label %9
40: ; preds = %9
ret i32 0
}

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