#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*/ abs(unsigned long long);
int floor(int /*<<< orphan*/);
int /*<<< orphan*/ log10(int /*<<< orphan*/);
unsigned long long pow(int, int);
int /*<<< orphan*/ printf(char *, unsigned long long);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int test = 0;
  unsigned long long int a = 0, n = 0, m = 0;
  int length = 0;
  unsigned long long int tempa = 0;
  scanf("%llu", &test);
  while (test > 0) {
    scanf("%llu", &a);
    scanf("%llu", &n);
    scanf("%llu", &m);
    length = floor(log10(abs(a))) + 1;
    tempa = a;
    --n;
    while (n > 0) {
      if (n == 1) {
        a = a * pow(10, length);
        a += tempa;
        --n;
      } else {
        a = a * pow(10, length * 2) + tempa * pow(10, length) + tempa;
        n = n - 2;
      }
      printf("\n%llu", a);
    }
    printf("%llu\n", a % m);
    --test;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
lea    0xe5d(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jle    1317 <main+0x1b7>
lea    0xe41(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xe2f(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xe1d(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <abs@plt>
mov    %eax,%edi
call   1070 <log10@plt>
mov    %eax,%edi
call   1080 <floor@plt>
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    12ee <main+0x18e>
cmpq   $0x1,-0x18(%rbp)
jne    1277 <main+0x117>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%esi
mov    $0xa,%edi
call   1060 <pow@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
imul   %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    12d9 <main+0x179>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x24(%rbp),%esi
shl    $0x1,%esi
mov    $0xa,%edi
call   1060 <pow@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
imul   %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x24(%rbp),%esi
mov    $0xa,%edi
call   1060 <pow@plt>
mov    -0x48(%rbp),%rcx
mov    %rax,%rdx
mov    -0x40(%rbp),%rax
imul   %rdx,%rcx
add    %rcx,%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xd1c(%rip),%rdi
call   1040 <printf@plt>
jmp    1220 <main+0xc0>
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
mov    %rdx,%rsi
lea    0xd02(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    11af <main+0x4f>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movl   $0x0,0xc(%rsp)
movq   $0x0,0x10(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x20(%rsp)
lea    0xe69(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    132b <main+0x1cb>
lea    0xe4a(%rip),%r13
jmp    1202 <main+0xa2>
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
mov    0x20(%rsp),%rcx
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     1320 <main+0x1c0>
xor    %edx,%edx
div    %rcx
mov    %rdx,%rsi
lea    0xe1d(%rip),%rdi
call   1040 <printf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
cmp    $0x1,%eax
jle    132b <main+0x1cb>
lea    0xdf8(%rip),%rbx
mov    %rbx,%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %rbx,%rdi
lea    0x18(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %rbx,%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x10(%rsp),%rdi
call   1030 <abs@plt>
mov    %eax,%edi
call   1070 <log10@plt>
mov    %eax,%edi
call   1080 <floor@plt>
mov    0x10(%rsp),%rbp
mov    0x18(%rsp),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x18(%rsp)
lea    (%rax,%rax,1),%r14d
add    $0x2,%r14d
mov    %eax,%r15d
add    $0x1,%r15d
jmp    12c5 <main+0x165>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rbx
mov    0x10(%rsp),%r13
mov    $0xa,%edi
mov    %r15d,%esi
call   1060 <pow@plt>
mov    %rax,%r12
imul   %r13,%r12
mov    %rbx,%r13
add    %rbp,%r12
mov    %r12,0x10(%rsp)
mov    0x18(%rsp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,0x18(%rsp)
mov    %r13,%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
mov    0x18(%rsp),%rcx
cmp    $0x1,%rcx
je     1280 <main+0x120>
test   %rcx,%rcx
je     11c0 <main+0x60>
mov    0x10(%rsp),%rbx
mov    $0xa,%edi
mov    %r14d,%esi
call   1060 <pow@plt>
mov    %rax,%r12
imul   %rbx,%r12
mov    $0xa,%edi
mov    %r15d,%esi
call   1060 <pow@plt>
imul   %rbp,%rax
add    %rbp,%r12
add    %rax,%r12
mov    %r12,0x10(%rsp)
mov    0x18(%rsp),%rax
add    $0xfffffffffffffffe,%rax
jmp    12b0 <main+0x150>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edx,%edx
div    %ecx
mov    %edx,%esi
jmp    11e2 <main+0x82>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%llu\00"
@.str.1 = [6 x i8] c"\0A%llu\00"
@.str.2 = [6 x i8] c"%llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %2
store i64 0, i64* %3
store i64 0, i64* %4
store i64 0, i64* %5
store i32 0, i32* %6
store i64 0, i64* %7
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %9
9: ; preds = %58, %0
%10 = load i32, i32* %2
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %65
12: ; preds = %9
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %3)
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %4)
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %5)
%16 = load i64, i64* %3
%17 = call i32 @abs(i64 %16)
%18 = call i32 @log10(i32 %17)
%19 = call i32 @floor(i32 %18)
%20 = add nsw i32 %19, 1
store i32 %20, i32* %6
%21 = load i64, i64* %3
store i64 %21, i64* %7
%22 = load i64, i64* %4
%23 = add i64 %22, -1
store i64 %23, i64* %4
br label %24
24: ; preds = %55, %12
%25 = load i64, i64* %4
%26 = icmp ugt i64 %25, 0
br i1 %26, label %27, label %58
27: ; preds = %24
%28 = load i64, i64* %4
%29 = icmp eq i64 %28, 1
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = load i64, i64* %3
%32 = load i32, i32* %6
%33 = call i64 @pow(i32 10, i32 %32)
%34 = mul i64 %31, %33
store i64 %34, i64* %3
%35 = load i64, i64* %7
%36 = load i64, i64* %3
%37 = add i64 %36, %35
store i64 %37, i64* %3
%38 = load i64, i64* %4
%39 = add i64 %38, -1
store i64 %39, i64* %4
br label %55
40: ; preds = %27
%41 = load i64, i64* %3
%42 = load i32, i32* %6
%43 = mul nsw i32 %42, 2
%44 = call i64 @pow(i32 10, i32 %43)
%45 = mul i64 %41, %44
%46 = load i64, i64* %7
%47 = load i32, i32* %6
%48 = call i64 @pow(i32 10, i32 %47)
%49 = mul i64 %46, %48
%50 = add i64 %45, %49
%51 = load i64, i64* %7
%52 = add i64 %50, %51
store i64 %52, i64* %3
%53 = load i64, i64* %4
%54 = sub i64 %53, 2
store i64 %54, i64* %4
br label %55
55: ; preds = %40, %30
%56 = load i64, i64* %3
%57 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %56)
br label %24
58: ; preds = %24
%59 = load i64, i64* %3
%60 = load i64, i64* %5
%61 = urem i64 %59, %60
%62 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %61)
%63 = load i32, i32* %2
%64 = add nsw i32 %63, -1
store i32 %64, i32* %2
br label %9
65: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%llu\00"
@.str.1 = [6 x i8] c"\0A%llu\00"
@.str.2 = [6 x i8] c"%llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%6 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%7 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%8 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %57
12: ; preds = %0, %49
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %2)
%14 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %3)
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %4)
%16 = load i64, i64* %2
%17 = call i32 @abs(i64 %16)
%18 = call i32 @log10(i32 %17)
%19 = call i32 @floor(i32 %18)
%20 = add nsw i32 %19, 1
%21 = load i64, i64* %2
%22 = load i64, i64* %3
%23 = add i64 %22, -1
store i64 %23, i64* %3
%24 = shl nsw i32 %20, 1
br label %25
25: ; preds = %44, %12
%26 = phi i64 [ %48, %44 ], [ %23, %12 ]
switch i64 %26, label %34 [
i64 0, label %49
i64 1, label %27
]
27: ; preds = %25
%28 = load i64, i64* %2
%29 = call i64 @pow(i32 10, i32 %20)
%30 = mul i64 %29, %28
%31 = add i64 %30, %21
store i64 %31, i64* %2
%32 = load i64, i64* %3
%33 = add i64 %32, -1
br label %44
34: ; preds = %25
%35 = load i64, i64* %2
%36 = call i64 @pow(i32 10, i32 %24)
%37 = mul i64 %36, %35
%38 = call i64 @pow(i32 10, i32 %20)
%39 = mul i64 %38, %21
%40 = add i64 %37, %21
%41 = add i64 %40, %39
store i64 %41, i64* %2
%42 = load i64, i64* %3
%43 = add i64 %42, -2
br label %44
44: ; preds = %34, %27
%45 = phi i64 [ %41, %34 ], [ %31, %27 ]
%46 = phi i64 [ %43, %34 ], [ %33, %27 ]
store i64 %46, i64* %3
%47 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %45)
%48 = load i64, i64* %3
br label %25
49: ; preds = %25
%50 = load i64, i64* %2
%51 = load i64, i64* %4
%52 = urem i64 %50, %51
%53 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %52)
%54 = load i32, i32* %1
%55 = add nsw i32 %54, -1
store i32 %55, i32* %1
%56 = icmp sgt i32 %54, 1
br i1 %56, label %12, label %57
57: ; preds = %49, %0
ret i32 0
}