#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*/ quickSort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int i, t, n, friends, sum, j;
  scanf("%d", &t);
  for (i = 1; i <= t; i++) {
    sum = 0;
    scanf("%d%d", &n, &friends);
    int stamps[friends];
    for (j = 0; j < friends; j++) {
      scanf("%d", &stamps[j]);
    }
    quickSort(stamps, 0, friends - 1);
    for (j = friends - 1; j >= 0; j--) {
      sum += stamps[j];
      if (sum >= n)
        break;
    }
    if (sum >= n)
      printf("Scenario #%d:\n%d\n", i, (friends - j));
    else
      printf("Scenario #%d:\nimpossible\n", i);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xebc(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     128d <main+0x15d>
movl   $0x0,-0x18(%rbp)
lea    0xe8e(%rip),%rdi
xor    %eax,%eax
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11e6 <main+0xb6>
mov    -0x38(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11af <main+0x7f>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1050 <quickSort@plt>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     123f <main+0x10f>
mov    -0x38(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     122c <main+0xfc>
jmp    123f <main+0x10f>
jmp    1231 <main+0x101>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1200 <main+0xd0>
mov    -0x18(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     1267 <main+0x137>
mov    -0x8(%rbp),%esi
mov    -0x14(%rbp),%edx
sub    -0x1c(%rbp),%edx
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1278 <main+0x148>
mov    -0x8(%rbp),%esi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1158 <main+0x28>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeba(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,-0x30(%rbp)
jle    1264 <main+0x134>
mov    $0x1,%r13d
lea    0xe98(%rip),%r12
jmp    1195 <main+0x65>
nopl   0x0(%rax)
lea    0xea0(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rsp
lea    0x1(%r13),%eax
cmp    -0x30(%rbp),%r13d
mov    %eax,%r13d
jge    1264 <main+0x134>
lea    0xe64(%rip),%rdi
lea    -0x34(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %rsp,%r14
mov    -0x2c(%rbp),%eax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x2c(%rbp),%edx
test   %edx,%edx
jle    1202 <main+0xd2>
mov    %r14,-0x40(%rbp)
mov    %r15,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rdx
add    $0x4,%r14
cmp    %rdx,%rbx
jl     11e0 <main+0xb0>
mov    -0x40(%rbp),%r14
add    $0xffffffff,%edx
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <quickSort@plt>
mov    -0x2c(%rbp),%edx
mov    -0x34(%rbp),%ecx
test   %edx,%edx
mov    $0x0,%eax
cmovs  %edx,%eax
add    $0xffffffff,%eax
mov    %rdx,%rsi
nopw   0x0(%rax,%rax,1)
test   %esi,%esi
jle    1244 <main+0x114>
add    $0xffffffffffffffff,%rsi
mov    %esi,%edi
add    (%r15,%rdi,4),%ebx
cmp    %ecx,%ebx
jl     1230 <main+0x100>
mov    %esi,%eax
cmp    %ecx,%ebx
jl     1170 <main+0x40>
sub    %eax,%edx
lea    0xdb0(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1181 <main+0x51>
xor    %eax,%eax
lea    -0x28(%rbp),%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 = [18 x i8] c"Scenario #%d:\0A%d\0A\00"
@.str.3 = [26 x i8] c"Scenario #%d:\0Aimpossible\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 i8*
%9 = alloca i64
store i32 0, i32* %1
%10 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 1, i32* %2
br label %11
11: ; preds = %72, %0
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %75
15: ; preds = %11
store i32 0, i32* %6
%16 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5)
%17 = load i32, i32* %5
%18 = zext i32 %17 to i64
%19 = call i8* @llvm.stacksave()
store i8* %19, i8** %8
%20 = alloca i32, i64 %18
store i64 %18, i64* %9
store i32 0, i32* %7
br label %21
21: ; preds = %30, %15
%22 = load i32, i32* %7
%23 = load i32, i32* %5
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %21
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %20, i64 %27
%29 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %28)
br label %30
30: ; preds = %25
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %21
33: ; preds = %21
%34 = load i32, i32* %5
%35 = sub nsw i32 %34, 1
%36 = call i32 @quickSort(i32* %20, i32 0, i32 %35)
%37 = load i32, i32* %5
%38 = sub nsw i32 %37, 1
store i32 %38, i32* %7
br label %39
39: ; preds = %54, %33
%40 = load i32, i32* %7
%41 = icmp sge i32 %40, 0
br i1 %41, label %42, label %57
42: ; preds = %39
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %20, i64 %44
%46 = load i32, i32* %45
%47 = load i32, i32* %6
%48 = add nsw i32 %47, %46
store i32 %48, i32* %6
%49 = load i32, i32* %6
%50 = load i32, i32* %4
%51 = icmp sge i32 %49, %50
br i1 %51, label %52, label %53
52: ; preds = %42
br label %57
53: ; preds = %42
br label %54
54: ; preds = %53
%55 = load i32, i32* %7
%56 = add nsw i32 %55, -1
store i32 %56, i32* %7
br label %39
57: ; preds = %52, %39
%58 = load i32, i32* %6
%59 = load i32, i32* %4
%60 = icmp sge i32 %58, %59
br i1 %60, label %61, label %67
61: ; preds = %57
%62 = load i32, i32* %2
%63 = load i32, i32* %5
%64 = load i32, i32* %7
%65 = sub nsw i32 %63, %64
%66 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %62, i32 %65)
br label %70
67: ; preds = %57
%68 = load i32, i32* %2
%69 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %68)
br label %70
70: ; preds = %67, %61
%71 = load i8*, i8** %8
br label %72
72: ; preds = %70
%73 = load i32, i32* %2
%74 = add nsw i32 %73, 1
store i32 %74, i32* %2
br label %11
75: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%d%d\00"
@.str.2 = [18 x i8] c"Scenario #%d:\0A%d\0A\00"
@.str.3 = [26 x i8] c"Scenario #%d:\0Aimpossible\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 1
br i1 %9, label %63, label %10
10: ; preds = %0, %59
%11 = phi i32 [ %60, %59 ], [ 1, %0 ]
%12 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%13 = load i32, i32* %3
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
%16 = alloca i32, i64 %14
%17 = load i32, i32* %3
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %10, %19
%20 = phi i64 [ %23, %19 ], [ 0, %10 ]
%21 = getelementptr inbounds i32, i32* %16, i64 %20
%22 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %21)
%23 = add nuw nsw i64 %20, 1
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %23, %25
br i1 %26, label %19, label %27
27: ; preds = %19, %10
%28 = phi i32 [ %17, %10 ], [ %24, %19 ]
%29 = add nsw i32 %28, -1
%30 = call i32 @quickSort(i32* %16, i32 0, i32 %29)
%31 = load i32, i32* %3
%32 = load i32, i32* %2
%33 = zext i32 %31 to i64
%34 = call i32 @llvm.smin.i32(i32 %31, i32 0)
%35 = add i32 %34, -1
br label %36
36: ; preds = %42, %27
%37 = phi i64 [ %39, %42 ], [ %33, %27 ]
%38 = phi i32 [ %46, %42 ], [ 0, %27 ]
%39 = add nsw i64 %37, -1
%40 = trunc i64 %37 to i32
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %50
42: ; preds = %36
%43 = and i64 %39, 4294967295
%44 = getelementptr inbounds i32, i32* %16, i64 %43
%45 = load i32, i32* %44
%46 = add nsw i32 %45, %38
%47 = icmp slt i32 %46, %32
br i1 %47, label %36, label %48
48: ; preds = %42
%49 = trunc i64 %39 to i32
br label %50
50: ; preds = %36, %48
%51 = phi i32 [ %49, %48 ], [ %35, %36 ]
%52 = phi i32 [ %46, %48 ], [ %38, %36 ]
%53 = icmp slt i32 %52, %32
br i1 %53, label %57, label %54
54: ; preds = %50
%55 = sub nsw i32 %31, %51
%56 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %55)
br label %59
57: ; preds = %50
%58 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %11)
br label %59
59: ; preds = %57, %54
%60 = add nuw nsw i32 %11, 1
%61 = load i32, i32* %1
%62 = icmp slt i32 %11, %61
br i1 %62, label %10, label %63
63: ; preds = %59, %0
ret i32 0
}