#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 *, unsigned long long);
int /*<<< orphan*/ scanf(char *, int *, ...);
int strlen(char *);
int main() {
  int T, i, tam, num;
  long long unsigned int N = 0, P = 0;
  char NK[30];
  scanf(" %d", &T);
  while (T > 0) {
    scanf("%d%s", &num, NK);
    tam = strlen(NK);
    N = num;
    i = 1;
    while (((num - (tam * i)) > 0)) {
      P = (num - (tam * i));
      N = N * P;
      i++;
    }
    printf("%llu\n", N);
    T--;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jle    11fc <main+0xcc>
lea    -0x50(%rbp),%rdx
lea    0xe8e(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
movslq -0x14(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%ecx
imul   -0xc(%rbp),%ecx
sub    %ecx,%eax
cmp    $0x0,%eax
jle    11de <main+0xae>
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%ecx
imul   -0xc(%rbp),%ecx
sub    %ecx,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
imul   -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119c <main+0x6c>
mov    -0x20(%rbp),%rsi
lea    0xe20(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1161 <main+0x31>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xebe(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
jle    11be <main+0x8e>
lea    0xea8(%rip),%r14
lea    0xc(%rsp),%r15
lea    0x10(%rsp),%rbx
lea    0xe9c(%rip),%r12
jmp    1188 <main+0x58>
nop
mov    %r12,%rdi
call   1040 <printf@plt>
mov    0x8(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0x8(%rsp)
cmp    $0x1,%eax
jle    11be <main+0x8e>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq 0xc(%rsp),%rsi
mov    %esi,%ecx
nopw   0x0(%rax,%rax,1)
sub    %eax,%ecx
test   %ecx,%ecx
jle    1170 <main+0x40>
mov    %ecx,%edx
imul   %rdx,%rsi
jmp    11b0 <main+0x80>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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