#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 **argv) {
  int cases, shops, shop;
  int closest, furthest;
  int i, j;
  scanf("%d", &cases);
  for (i = 0; i < cases; i++) {
    scanf("%d", &shops);
    scanf("%d", &closest);
    furthest = closest;
    for (j = 1; j < shops; j++) {
      scanf("%d", &shop);
      if (shop > furthest)
        furthest = shop;
      if (shop < closest)
        closest = shop;
    }
    printf("%d\n", (furthest - closest) << 1);
  }
  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    0xec3(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11fc <main+0xdc>
lea    0xea0(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xe90(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11d9 <main+0xb9>
lea    0xe67(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    11b4 <main+0x94>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11c6 <main+0xa6>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11cb <main+0xab>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1186 <main+0x66>
mov    -0x24(%rbp),%esi
sub    -0x20(%rbp),%esi
shl    $0x1,%esi
lea    0xe1a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    114d <main+0x2d>
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    0xecb(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0x10(%rsp)
jle    11ef <main+0xcf>
xor    %r14d,%r14d
lea    0xeac(%rip),%rbx
lea    0x14(%rsp),%r12
lea    0xea3(%rip),%r13
jmp    118b <main+0x6b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%eax
sub    %eax,%ebp
add    %ebp,%ebp
mov    %r13,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0x1,%r14d
cmp    0x10(%rsp),%r14d
jge    11ef <main+0xcf>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x8(%rsp),%ebp
cmpl   $0x2,0xc(%rsp)
jl     1170 <main+0x50>
mov    $0x1,%r15d
jmp    11cb <main+0xab>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15d
cmp    0xc(%rsp),%r15d
jge    1172 <main+0x52>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
mov    0x14(%rsp),%ecx
cmp    %ebp,%ecx
cmovg  %ecx,%ebp
mov    0x8(%rsp),%eax
cmp    %eax,%ecx
jge    11c0 <main+0xa0>
mov    %ecx,0x8(%rsp)
mov    %ecx,%eax
jmp    11c0 <main+0xa0>
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 = [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 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
store i32 0, i32* %11
br label %14
14: ; preds = %49, %2
%15 = load i32, i32* %11
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %52
18: ; preds = %14
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
%21 = load i32, i32* %9
store i32 %21, i32* %10
store i32 1, i32* %12
br label %22
22: ; preds = %40, %18
%23 = load i32, i32* %12
%24 = load i32, i32* %7
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %43
26: ; preds = %22
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%28 = load i32, i32* %8
%29 = load i32, i32* %10
%30 = icmp sgt i32 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = load i32, i32* %8
store i32 %32, i32* %10
br label %33
33: ; preds = %31, %26
%34 = load i32, i32* %8
%35 = load i32, i32* %9
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = load i32, i32* %8
store i32 %38, i32* %9
br label %39
39: ; preds = %37, %33
br label %40
40: ; preds = %39
%41 = load i32, i32* %12
%42 = add nsw i32 %41, 1
store i32 %42, i32* %12
br label %22
43: ; preds = %22
%44 = load i32, i32* %10
%45 = load i32, i32* %9
%46 = sub nsw i32 %44, %45
%47 = shl i32 %46, 1
%48 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %43
%50 = load i32, i32* %11
%51 = add nsw i32 %50, 1
store i32 %51, i32* %11
br label %14
52: ; preds = %14
ret i32 0
}

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