#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 *, long long);
int /*<<< orphan*/ scanf(char *, long long *);
int main() {
  long long int i, a, j, k, t, n;
  scanf("%lld", &t);
  while (t--) {
    j = 1;
    scanf("%lld", &n);
    for (i = 0; i < (n - 1); i++) {
      scanf("%lld", &a);
      j = (j * a) % 1234567;
    }
    printf("%lld\n", j);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x30(%rbp)
cmp    $0x0,%rax
je     11da <main+0xba>
movq   $0x1,-0x20(%rbp)
lea    0xe99(%rip),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <scanf@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jge    11c5 <main+0xa5>
lea    0xe6c(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x20(%rbp),%rax
imul   -0x18(%rbp),%rax
mov    $0x12d687,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1178 <main+0x58>
mov    -0x20(%rbp),%rsi
lea    0xe35(%rip),%rdi
call   1030 <printf@plt>
jmp    113f <main+0x1f>
xor    %eax,%eax
add    $0x40,%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    0xecb(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
subq   $0x1,0x8(%rsp)
jae    1158 <main+0x38>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xea1(%rip),%r13
lea    0x10(%rsp),%r15
movabs $0x365bb44649a1e167,%rbp
b4 5b 36
lea    0xe90(%rip),%r12
jmp    1193 <main+0x73>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
subq   $0x1,0x8(%rsp)
jb     1147 <main+0x27>
mov    %r13,%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    $0x1,%ebx
cmpq   $0x2,(%rsp)
jl     1180 <main+0x60>
mov    $0x1,%ebx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
imul   0x10(%rsp),%rbx
mov    %rbx,%rax
imul   %rbp
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%rdx
add    %rax,%rdx
imul   $0x12d687,%rdx,%rax
sub    %rax,%rbx
add    $0x1,%r14
mov    (%rsp),%rax
add    $0xffffffffffffffff,%rax
cmp    %rax,%r14
jl     11c0 <main+0xa0>
jmp    1180 <main+0x60>

LLVM IR (-O0):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [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 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %6)
br label %9
9: ; preds = %29, %0
%10 = load i64, i64* %6
%11 = add nsw i64 %10, -1
store i64 %11, i64* %6
%12 = icmp ne i64 %10, 0
br i1 %12, label %13, label %32
13: ; preds = %9
store i64 1, i64* %4
%14 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %7)
store i64 0, i64* %2
br label %15
15: ; preds = %26, %13
%16 = load i64, i64* %2
%17 = load i64, i64* %7
%18 = sub nsw i64 %17, 1
%19 = icmp slt i64 %16, %18
br i1 %19, label %20, label %29
20: ; preds = %15
%21 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %3)
%22 = load i64, i64* %4
%23 = load i64, i64* %3
%24 = mul nsw i64 %22, %23
%25 = srem i64 %24, 1234567
store i64 %25, i64* %4
br label %26
26: ; preds = %20
%27 = load i64, i64* %2
%28 = add nsw i64 %27, 1
store i64 %28, i64* %2
br label %15
29: ; preds = %15
%30 = load i64, i64* %4
%31 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %30)
br label %9
32: ; preds = %9
ret i32 0
}

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