#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 /*<<< orphan*/ quicksort(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int t, s, f, i, x, j = 1, k;
  scanf("%d", &t);
  while (t--) {
    k = 0;
    x = 0;
    scanf("%d %d", &s, &f);
    int sf[f];
    for (i = 0; i < f; i++)
      scanf("%d", &sf[i]);
    quicksort(sf, 0, f - 1);
    for (i = f - 1; x < s; i--) {
      x += sf[i];
      k++;
    }
    printf("Scenario #%d:\n", j);
    if (k > f)
      printf("impossible\n\n");
    else
      printf("%d\n\n", k);
    j++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x1c(%rbp)
lea    0xeb6(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1299 <main+0x169>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1050 <scanf@plt>
mov    -0x10(%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,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11f5 <main+0xc5>
mov    -0x38(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11be <main+0x8e>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <quicksort@plt>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1243 <main+0x113>
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    120f <main+0xdf>
mov    -0x1c(%rbp),%esi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    1273 <main+0x143>
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1284 <main+0x154>
mov    -0x20(%rbp),%esi
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
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    0xeab(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
subl   $0x1,-0x30(%rbp)
jae    117a <main+0x3a>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r13d
lea    0xe7c(%rip),%r14
jmp    11ae <main+0x6e>
nopl   0x0(%rax)
lea    0xe7e(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rsp
add    $0x1,%r13d
subl   $0x1,-0x30(%rbp)
jb     1169 <main+0x29>
lea    0xe4b(%rip),%rdi
lea    -0x34(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %rsp,%rbx
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    1212 <main+0xd2>
mov    %rbx,-0x40(%rbp)
mov    %r15,%r12
xor    %ebx,%ebx
nop
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rdx
add    $0x4,%r12
cmp    %rdx,%rbx
jl     11f0 <main+0xb0>
mov    -0x40(%rbp),%rbx
add    $0xffffffff,%edx
xor    %r12d,%r12d
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <quicksort@plt>
mov    -0x34(%rbp),%eax
test   %eax,%eax
jle    124e <main+0x10e>
movslq -0x2c(%rbp),%rcx
lea    (%r15,%rcx,4),%rcx
add    $0xfffffffffffffffc,%rcx
xor    %edx,%edx
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
add    (%rcx),%edx
add    $0x1,%r12d
add    $0xfffffffffffffffc,%rcx
cmp    %eax,%edx
jl     1240 <main+0x100>
lea    0xdb1(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    -0x2c(%rbp),%r12d
jle    1190 <main+0x50>
lea    0xdaa(%rip),%rdi
call   1030 <puts@plt>
jmp    11a1 <main+0x61>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [15 x i8] c"Scenario #%d:\0A\00"
@.str.3 = [13 x i8] c"impossible\0A\0A\00"
@.str.4 = [5 x i8] c"%d\0A\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
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %1
store i32 1, i32* %7
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %12
12: ; preds = %67, %0
%13 = load i32, i32* %2
%14 = add nsw i32 %13, -1
store i32 %14, i32* %2
%15 = icmp ne i32 %13, 0
br i1 %15, label %16, label %71
16: ; preds = %12
store i32 0, i32* %8
store i32 0, i32* %6
%17 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
%18 = load i32, i32* %4
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %9
%21 = alloca i32, i64 %19
store i64 %19, i64* %10
store i32 0, i32* %5
br label %22
22: ; preds = %31, %16
%23 = load i32, i32* %5
%24 = load i32, i32* %4
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %34
26: ; preds = %22
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %21, i64 %28
%30 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %29)
br label %31
31: ; preds = %26
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %22
34: ; preds = %22
%35 = load i32, i32* %4
%36 = sub nsw i32 %35, 1
%37 = call i32 @quicksort(i32* %21, i32 0, i32 %36)
%38 = load i32, i32* %4
%39 = sub nsw i32 %38, 1
store i32 %39, i32* %5
br label %40
40: ; preds = %53, %34
%41 = load i32, i32* %6
%42 = load i32, i32* %3
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %56
44: ; preds = %40
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %21, i64 %46
%48 = load i32, i32* %47
%49 = load i32, i32* %6
%50 = add nsw i32 %49, %48
store i32 %50, i32* %6
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %53
53: ; preds = %44
%54 = load i32, i32* %5
%55 = add nsw i32 %54, -1
store i32 %55, i32* %5
br label %40
56: ; preds = %40
%57 = load i32, i32* %7
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %8
%60 = load i32, i32* %4
%61 = icmp sgt i32 %59, %60
br i1 %61, label %62, label %64
62: ; preds = %56
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %67
64: ; preds = %56
%65 = load i32, i32* %8
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %64, %62
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
store i32 %69, i32* %7
%70 = load i8*, i8** %9
br label %12
71: ; preds = %12
ret i32 0
}

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