#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 max(int, int);
int min(int, int);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main(void) {
  int N;
  scanf("%d", &N);
  while (N-- > 0) {
    int L, M;
    scanf("%d%d", &L, &M);
    int x = 0, y = 0, i;
    for (i = 0; i < M; i++) {
      int a;
      scanf("%d", &a);
      x = max(x, min(a, L - a));
      y = max(y, max(a, L - a));
    }
    printf("%d %d\n", x, y);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeac(%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    1225 <main+0xe5>
lea    0xe84(%rip),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    120e <main+0xce>
lea    0xe4f(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%edi
mov    -0xc(%rbp),%esi
sub    -0x20(%rbp),%esi
call   1040 <min@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%esi
call   1050 <max@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    -0xc(%rbp),%esi
sub    -0x20(%rbp),%esi
call   1050 <max@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1050 <max@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a0 <main+0x60>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xdea(%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    0xead(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x8(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x8(%rsp)
test   %eax,%eax
jle    1245 <main+0x105>
lea    0xe87(%rip),%r13
lea    0xc(%rsp),%rbx
lea    0xe7e(%rip),%rbp
jmp    11b1 <main+0x71>
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
call   1030 <printf@plt>
mov    0x8(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x8(%rsp)
test   %eax,%eax
jle    1245 <main+0x105>
lea    0xe48(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,0x10(%rsp)
mov    $0x0,%r15d
mov    $0x0,%r14d
jle    1190 <main+0x50>
xor    %r12d,%r12d
xor    %r14d,%r14d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0xc(%rsp),%edi
mov    0x14(%rsp),%esi
sub    %edi,%esi
call   1040 <min@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1050 <max@plt>
mov    %eax,%r15d
mov    0xc(%rsp),%edi
mov    0x14(%rsp),%esi
sub    %edi,%esi
call   1050 <max@plt>
mov    %r14d,%edi
mov    %eax,%esi
call   1050 <max@plt>
mov    %eax,%r14d
add    $0x1,%r12d
cmp    0x10(%rsp),%r12d
jl     11f0 <main+0xb0>
jmp    1190 <main+0x50>
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"%d%d\00"
@.str.2 = [7 x i8] c"%d %d\0A\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 i32
store i32 0, i32* %1
%9 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %10
10: ; preds = %39, %0
%11 = load i32, i32* %2
%12 = add nsw i32 %11, -1
store i32 %12, i32* %2
%13 = icmp sgt i32 %11, 0
br i1 %13, label %14, label %43
14: ; preds = %10
%15 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %16
16: ; preds = %36, %14
%17 = load i32, i32* %7
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %39
20: ; preds = %16
%21 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%22 = load i32, i32* %5
%23 = load i32, i32* %8
%24 = load i32, i32* %3
%25 = load i32, i32* %8
%26 = sub nsw i32 %24, %25
%27 = call i32 @min(i32 %23, i32 %26)
%28 = call i32 @max(i32 %22, i32 %27)
store i32 %28, i32* %5
%29 = load i32, i32* %6
%30 = load i32, i32* %8
%31 = load i32, i32* %3
%32 = load i32, i32* %8
%33 = sub nsw i32 %31, %32
%34 = call i32 @max(i32 %30, i32 %33)
%35 = call i32 @max(i32 %29, i32 %34)
store i32 %35, i32* %6
br label %36
36: ; preds = %20
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %16
39: ; preds = %16
%40 = load i32, i32* %5
%41 = load i32, i32* %6
%42 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %40, i32 %41)
br label %10
43: ; preds = %10
ret i32 0
}

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