#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 *, double);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ scanf(char *, int *, ...);
double sigma(int *, int);
int main(void) {
  int T, N, Q, i, j, k, arr[10000], a, b;
  double s;
  scanf("%d", &T);
  for (i = 0; i < T; i++) {
    scanf("%d", &N);
    for (j = 0; j < N; j++)
      scanf("%d", &arr[j]);
    scanf("%d", &Q);
    s = sigma(arr, N);
    printf("%.2f\n", s);
    for (j = 0; j < Q; j++) {
      scanf("%d %d", &a, &b);
      printf("%.2f\n", s * (a < 0 ? -a : a));
    }
    putchar('\n');
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb0(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12ba <main+0x17a>
lea    0xe8b(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ca <main+0x8a>
movslq -0x18(%rbp),%rax
lea    -0x9c60(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1190 <main+0x50>
lea    0xe38(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x9c60(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <sigma@plt>
movsd  %xmm0,-0x9c70(%rbp)
ff
movsd  -0x9c70(%rbp),%xmm0
ff
lea    0xdfe(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12a2 <main+0x162>
lea    0xde5(%rip),%rdi
lea    -0x9c64(%rbp),%rsi
lea    -0x9c68(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
movsd  -0x9c70(%rbp),%xmm0
ff
movsd  %xmm0,-0x9c78(%rbp)
ff
cmpl   $0x0,-0x9c64(%rbp)
jge    1266 <main+0x126>
xor    %eax,%eax
sub    -0x9c64(%rbp),%eax
mov    %eax,-0x9c7c(%rbp)
jmp    1272 <main+0x132>
mov    -0x9c64(%rbp),%eax
mov    %eax,-0x9c7c(%rbp)
movsd  -0x9c78(%rbp),%xmm0
ff
mov    -0x9c7c(%rbp),%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
lea    0xd71(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    120e <main+0xce>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116b <main+0x2b>
xor    %eax,%eax
add    $0x9c80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x9c78,%rsp
lea    0xeb1(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,0x14(%rsp)
jle    126e <main+0x12e>
lea    0xe93(%rip),%r14
lea    0xe83(%rip),%r13
lea    0xe82(%rip),%r15
lea    0x2c(%rsp),%r12
xor    %eax,%eax
jmp    11ab <main+0x6b>
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x18(%rsp),%eax
add    $0x1,%eax
cmp    0x14(%rsp),%eax
jge    126e <main+0x12e>
mov    %eax,0x18(%rsp)
mov    %r15,%rbx
mov    %r14,%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11ef <main+0xaf>
lea    0x30(%rsp),%r15
xor    %ebp,%ebp
nop
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
add    $0x4,%r15
cmp    %rax,%rbp
jl     11d0 <main+0x90>
mov    %r14,%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
lea    0x30(%rsp),%rdi
call   1040 <sigma@plt>
mov    %r13,%rdi
movsd  %xmm0,0x20(%rsp)
call   1050 <printf@plt>
cmpl   $0x0,0x10(%rsp)
mov    %rbx,%r15
lea    0x1c(%rsp),%rbx
jle    1190 <main+0x50>
xor    %ebp,%ebp
nop
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x1c(%rsp),%eax
mov    %eax,%ecx
neg    %ecx
cmovs  %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mulsd  0x20(%rsp),%xmm0
mov    %r13,%rdi
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    0x10(%rsp),%ebp
jl     1230 <main+0xf0>
jmp    1190 <main+0x50>
xor    %eax,%eax
add    $0x9c78,%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 = [6 x i8] c"%.2f\0A\00"
@.str.2 = [6 x i8] c"%d %d\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 [10000 x i32]
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
store i32 0, i32* %1
%12 = 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* %5
br label %13
13: ; preds = %62, %0
%14 = load i32, i32* %5
%15 = load i32, i32* %2
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %65
17: ; preds = %13
%18 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 0, i32* %6
br label %19
19: ; preds = %28, %17
%20 = load i32, i32* %6
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [10000 x i32], [10000 x i32]* %8, i64 0, i64 %25
%27 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %26)
br label %28
28: ; preds = %23
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %19
31: ; preds = %19
%32 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%33 = getelementptr inbounds [10000 x i32], [10000 x i32]* %8, i64 0, i64 0
%34 = load i32, i32* %3
%35 = call double @sigma(i32* %33, i32 %34)
store double %35, double* %11
%36 = load double, double* %11
%37 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %36)
store i32 0, i32* %6
br label %38
38: ; preds = %57, %31
%39 = load i32, i32* %6
%40 = load i32, i32* %4
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %60
42: ; preds = %38
%43 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %9, i32* %10)
%44 = load double, double* %11
%45 = load i32, i32* %9
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = load i32, i32* %9
%49 = sub nsw i32 0, %48
br label %52
50: ; preds = %42
%51 = load i32, i32* %9
br label %52
52: ; preds = %50, %47
%53 = phi i32 [ %49, %47 ], [ %51, %50 ]
%54 = sitofp i32 %53 to double
%55 = fmul double %44, %54
%56 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %55)
br label %57
57: ; preds = %52
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 1
store i32 %59, i32* %6
br label %38
60: ; preds = %38
%61 = call i32 @putchar(i8 signext 10)
br label %62
62: ; preds = %60
%63 = load i32, i32* %5
%64 = add nsw i32 %63, 1
store i32 %64, i32* %5
br label %13
65: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%.2f\0A\00"
@.str.2 = [6 x i8] c"%d %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10000 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %1 to i8*
%8 = bitcast i32* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = bitcast [10000 x i32]* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %54
16: ; preds = %0
%17 = getelementptr inbounds [10000 x i32], [10000 x i32]* %4, i64 0, i64 0
br label %18
18: ; preds = %16, %49
%19 = phi i32 [ 0, %16 ], [ %51, %49 ]
%20 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%21 = load i32, i32* %2
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %31
23: ; preds = %18, %23
%24 = phi i64 [ %27, %23 ], [ 0, %18 ]
%25 = getelementptr inbounds [10000 x i32], [10000 x i32]* %4, i64 0, i64 %24
%26 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %25)
%27 = add nuw nsw i64 %24, 1
%28 = load i32, i32* %2
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %23, label %31
31: ; preds = %23, %18
%32 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%33 = load i32, i32* %2
%34 = call double @sigma(i32* %17, i32 %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %34)
%36 = load i32, i32* %3
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %49
38: ; preds = %31, %38
%39 = phi i32 [ %46, %38 ], [ 0, %31 ]
%40 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %5, i32* %6)
%41 = load i32, i32* %5
%42 = call i32 @llvm.abs.i32(i32 %41, i1 true)
%43 = sitofp i32 %42 to double
%44 = fmul double %34, %43
%45 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), double %44)
%46 = add nuw nsw i32 %39, 1
%47 = load i32, i32* %3
%48 = icmp slt i32 %46, %47
br i1 %48, label %38, label %49
49: ; preds = %38, %31
%50 = call i32 @putchar(i8 signext 10)
%51 = add nuw nsw i32 %19, 1
%52 = load i32, i32* %1
%53 = icmp slt i32 %51, %52
br i1 %53, label %18, label %54
54: ; preds = %49, %0
ret i32 0
}