#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
char *strtok(char *, char *);
int main() {
  int n = 0;
  char buffer[100000];
  fgets(buffer, sizeof(buffer), stdin);
  n = atoi(buffer);
  for (int i = 0; i < n; i++) {
    fgets(buffer, sizeof(buffer), stdin);
    fgets(buffer, sizeof(buffer), stdin);
    int positions[1000000];
    int j = 0;
    char *token = strtok(buffer, " ");
    while (token) {
      positions[j++] = atoi(token);
      token = strtok(NULL, " ");
    }
    fgets(buffer, sizeof(buffer), stdin);
    const char *array[j];
    int k = 0;
    token = strtok(buffer, " \n");
    while (token) {
      array[--positions[k++]] = token;
      token = strtok(NULL, " \n");
    }
    for (int t = 0; t < j; t++) {
      printf("%s\n", array[t]);
    }
    if (i < n - 1) {
      printf("\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3e8ff0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x186b0(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
mov    $0x186a0,%esi
call   1040 <fgets@plt>
lea    -0x186b0(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x186b4(%rbp)
mov    -0x186b4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13aa <main+0x26a>
lea    -0x186b0(%rbp),%rdi
mov    0x2e3f(%rip),%rax
mov    (%rax),%edx
mov    $0x186a0,%esi
call   1040 <fgets@plt>
lea    -0x186b0(%rbp),%rdi
mov    0x2e25(%rip),%rax
mov    (%rax),%edx
mov    $0x186a0,%esi
call   1040 <fgets@plt>
movl   $0x0,-0x3e8fc4(%rbp)
lea    -0x186b0(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x3e8fd0(%rbp)
cmpq   $0x0,-0x3e8fd0(%rbp)
je     1245 <main+0x105>
mov    -0x3e8fd0(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x3e8fc4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x3e8fc4(%rbp)
cltq
mov    %ecx,-0x3e8fc0(%rbp,%rax,4)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdcc(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x3e8fd0(%rbp)
jmp    11f3 <main+0xb3>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edx
lea    -0x186b0(%rbp),%rdi
mov    $0x186a0,%esi
call   1040 <fgets@plt>
mov    -0x3e8fc4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x3e8fd8(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x3e8ff0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x3e8fe0(%rbp)
movl   $0x0,-0x3e8fe4(%rbp)
lea    -0x186b0(%rbp),%rdi
lea    0xd58(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x3e8fd0(%rbp)
cmpq   $0x0,-0x3e8fd0(%rbp)
je     131a <main+0x1da>
mov    -0x3e8ff0(%rbp),%rax
mov    -0x3e8fd0(%rbp),%rdx
mov    -0x3e8fe4(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x3e8fe4(%rbp)
movslq %ecx,%rsi
mov    -0x3e8fc0(%rbp,%rsi,4),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x3e8fc0(%rbp,%rsi,4)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
xor    %eax,%eax
mov    %eax,%edi
lea    0xcf9(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x3e8fd0(%rbp)
jmp    12b6 <main+0x176>
movl   $0x0,-0x3e8fe8(%rbp)
mov    -0x3e8fe8(%rbp),%eax
cmp    -0x3e8fc4(%rbp),%eax
jge    136a <main+0x22a>
mov    -0x3e8ff0(%rbp),%rax
movslq -0x3e8fe8(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xcb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3e8fe8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3e8fe8(%rbp)
jmp    1324 <main+0x1e4>
mov    -0x186b4(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    138c <main+0x24c>
lea    0xc7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3e8fd8(%rbp),%rax
mov    %rax,%rsp
mov    -0x186b4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x186b4(%rbp)
jmp    118c <main+0x4c>
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    $0x3e8fc8,%rsp
mov    0x2e7d(%rip),%r15
mov    (%r15),%edx
lea    -0x186f0(%rbp),%rbx
mov    %rbx,%rdi
mov    $0x186a0,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1070 <atoi@plt>
mov    %rax,-0x38(%rbp)
test   %eax,%eax
jle    12ef <main+0x19f>
mov    -0x38(%rbp),%rax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
xor    %ebx,%ebx
lea    0xe57(%rip),%r12
lea    0xe52(%rip),%r14
jmp    11d7 <main+0x87>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    -0x40(%rbp),%rsp
add    $0x1,%ebx
cmp    -0x38(%rbp),%ebx
mov    0x2e17(%rip),%r15
je     12ef <main+0x19f>
mov    %rbx,-0x48(%rbp)
mov    (%r15),%edx
lea    -0x186f0(%rbp),%rbx
mov    %rbx,%rdi
mov    $0x186a0,%esi
call   1050 <fgets@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x186a0,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strtok@plt>
mov    $0x0,%ebx
test   %rax,%rax
je     1242 <main+0xf2>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %eax,-0x3e8ff0(%rbp,%rbx,4)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r12,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
jne    1220 <main+0xd0>
mov    (%r15),%edx
lea    -0x186f0(%rbp),%rdi
mov    $0x186a0,%esi
call   1050 <fgets@plt>
mov    %rsp,-0x40(%rbp)
mov    %ebx,%r15d
mov    %rsp,%r13
lea    0xf(,%r15,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    -0x186f0(%rbp),%rdi
mov    %r14,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     12b1 <main+0x161>
lea    -0x3e8ff0(%rbp),%rbx
nopl   (%rax)
movslq (%rbx),%rcx
lea    -0x1(%rcx),%rdx
mov    %edx,(%rbx)
mov    %rax,-0x8(%r13,%rcx,8)
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <strtok@plt>
add    $0x4,%rbx
test   %rax,%rax
jne    1290 <main+0x140>
test   %r15,%r15
je     12d3 <main+0x183>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,8),%rdi
call   1040 <puts@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    12c0 <main+0x170>
mov    -0x48(%rbp),%rbx
cmp    -0x2c(%rbp),%ebx
jge    11c0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11c0 <main+0x70>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c" \0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100000 x i8]
%4 = alloca i32
%5 = alloca [1000000 x i32]
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%12 = getelementptr inbounds [100000 x i8], [100000 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %12, i32 100000, i32 %13)
%15 = getelementptr inbounds [100000 x i8], [100000 x i8]* %3, i64 0, i64 0
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %2
store i32 0, i32* %4
br label %17
17: ; preds = %88, %0
%18 = load i32, i32* %4
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %91
21: ; preds = %17
%22 = getelementptr inbounds [100000 x i8], [100000 x i8]* %3, i64 0, i64 0
%23 = load i32, i32* @stdin
%24 = call i32 @fgets(i8* %22, i32 100000, i32 %23)
%25 = getelementptr inbounds [100000 x i8], [100000 x i8]* %3, i64 0, i64 0
%26 = load i32, i32* @stdin
%27 = call i32 @fgets(i8* %25, i32 100000, i32 %26)
store i32 0, i32* %6
%28 = getelementptr inbounds [100000 x i8], [100000 x i8]* %3, i64 0, i64 0
%29 = call i8* @strtok(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %29, i8** %7
br label %30
30: ; preds = %33, %21
%31 = load i8*, i8** %7
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = load i8*, i8** %7
%35 = call i32 @atoi(i8* %34)
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %5, i64 0, i64 %38
store i32 %35, i32* %39
%40 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %40, i8** %7
br label %30
41: ; preds = %30
%42 = getelementptr inbounds [100000 x i8], [100000 x i8]* %3, i64 0, i64 0
%43 = load i32, i32* @stdin
%44 = call i32 @fgets(i8* %42, i32 100000, i32 %43)
%45 = load i32, i32* %6
%46 = zext i32 %45 to i64
%47 = call i8* @llvm.stacksave()
store i8* %47, i8** %8
%48 = alloca i8*, i64 %46
store i64 %46, i64* %9
store i32 0, i32* %10
%49 = getelementptr inbounds [100000 x i8], [100000 x i8]* %3, i64 0, i64 0
%50 = call i8* @strtok(i8* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %50, i8** %7
br label %51
51: ; preds = %54, %41
%52 = load i8*, i8** %7
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %65
54: ; preds = %51
%55 = load i8*, i8** %7
%56 = load i32, i32* %10
%57 = add nsw i32 %56, 1
store i32 %57, i32* %10
%58 = sext i32 %56 to i64
%59 = getelementptr inbounds [1000000 x i32], [1000000 x i32]* %5, i64 0, i64 %58
%60 = load i32, i32* %59
%61 = add nsw i32 %60, -1
store i32 %61, i32* %59
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8*, i8** %48, i64 %62
store i8* %55, i8** %63
%64 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i8* %64, i8** %7
br label %51
65: ; preds = %51
store i32 0, i32* %11
br label %66
66: ; preds = %76, %65
%67 = load i32, i32* %11
%68 = load i32, i32* %6
%69 = icmp slt i32 %67, %68
br i1 %69, label %70, label %79
70: ; preds = %66
%71 = load i32, i32* %11
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8*, i8** %48, i64 %72
%74 = load i8*, i8** %73
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %70
%77 = load i32, i32* %11
%78 = add nsw i32 %77, 1
store i32 %78, i32* %11
br label %66
79: ; preds = %66
%80 = load i32, i32* %4
%81 = load i32, i32* %2
%82 = sub nsw i32 %81, 1
%83 = icmp slt i32 %80, %82
br i1 %83, label %84, label %86
84: ; preds = %79
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %86
86: ; preds = %84, %79
%87 = load i8*, i8** %8
br label %88
88: ; preds = %86
%89 = load i32, i32* %4
%90 = add nsw i32 %89, 1
store i32 %90, i32* %4
br label %17
91: ; preds = %17
ret i32 0
}

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