#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 *, long long);
int /*<<< orphan*/ scanf(char *, ...);
int strlen(char *);
int main() {
  char entrada[21];
  int n, k, i, c;
  long long r;
  scanf("%d", &c);
  for (i = 0; i < c; i++) {
    scanf("%d", &n);
    scanf("%s", entrada);
    k = strlen(entrada);
    for (r = 1; n > 1; n -= k)
      r *= n;
    printf("%lld\n", r);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    11e1 <main+0xb1>
lea    0xe95(%rip),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
movq   $0x1,-0x38(%rbp)
cmpl   $0x1,-0x24(%rbp)
jle    11c3 <main+0x93>
movslq -0x24(%rbp),%rax
imul   -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
jmp    119c <main+0x6c>
mov    -0x38(%rbp),%rsi
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1158 <main+0x28>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xebb(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11e3 <main+0xb3>
lea    0xe9d(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xe94(%rip),%r12
lea    0x10(%rsp),%rbx
lea    0xe8b(%rip),%r13
xor    %ebp,%ebp
jmp    1191 <main+0x61>
nop
mov    %r13,%rdi
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    0x8(%rsp),%ebp
jge    11e3 <main+0xb3>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    0xc(%rsp),%ecx
mov    $0x1,%esi
cmp    $0x2,%ecx
jl     1180 <main+0x50>
mov    $0x1,%esi
cs nopw 0x0(%rax,%rax,1)
mov    %ecx,%edx
imul   %rdx,%rsi
sub    %eax,%ecx
cmp    $0x1,%ecx
jg     11d0 <main+0xa0>
mov    %ecx,0xc(%rsp)
jmp    1180 <main+0x50>
xor    %eax,%eax
add    $0x28,%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 = [3 x i8] c"%s\00"
@.str.2 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [21 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
store i32 0, i32* %5
br label %9
9: ; preds = %34, %0
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %37
13: ; preds = %9
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%15 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 0
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [21 x i8], [21 x i8]* %2, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %4
store i64 1, i64* %7
br label %19
19: ; preds = %27, %13
%20 = load i32, i32* %3
%21 = icmp sgt i32 %20, 1
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = load i64, i64* %7
%26 = mul nsw i64 %25, %24
store i64 %26, i64* %7
br label %27
27: ; preds = %22
%28 = load i32, i32* %4
%29 = load i32, i32* %3
%30 = sub nsw i32 %29, %28
store i32 %30, i32* %3
br label %19
31: ; preds = %19
%32 = load i64, i64* %7
%33 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %32)
br label %34
34: ; preds = %31
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %9
37: ; preds = %9
%38 = load i32, i32* %1
ret i32 %38
}

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