#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 */
char getchar();
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int main() {
  int t, i, j, pos, index[1000];
  const long size = 10000;
  char c, data[10000][15], sort[10000][15];
  scanf("%d", &t);
  for (i = 0; i < t; i++) {
    pos = 0;
    if (i)
      putchar('\n');
    scanf("%d", &index[pos++]);
    while ((c = getchar()) != '\n')
      scanf("%d", &index[pos++]);
    pos = 0;
    scanf("%s", data[pos++]);
    while ((c = getchar()) != '\n')
      scanf("%s", data[pos++]);
    for (j = 0; j < pos; j++)
      strcpy(sort[index[j]], data[j]);
    for (j = 1; j <= pos; j++)
      puts(sort[j]);
  }
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a3b0,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x2710,-0xfc8(%rbp)
lea    0xe8c(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1331 <main+0x1e1>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11ad <main+0x5d>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
cltq
lea    -0xfc0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0xfc9(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     121d <main+0xcd>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
cltq
lea    -0xfc0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
jmp    11d6 <main+0x86>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
cltq
lea    -0x259c0(%rbp),%rsi
imul   $0xf,%rax,%rax
add    %rax,%rsi
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %al,-0xfc9(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     1294 <main+0x144>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
cltq
lea    -0x259c0(%rbp),%rsi
imul   $0xf,%rax,%rax
add    %rax,%rsi
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1070 <scanf@plt>
jmp    124d <main+0xfd>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12e6 <main+0x196>
movslq -0x10(%rbp),%rax
movslq -0xfc0(%rbp,%rax,4),%rax
ff
lea    -0x4a3b0(%rbp),%rdi
imul   $0xf,%rax,%rax
add    %rax,%rdi
movslq -0x10(%rbp),%rax
lea    -0x259c0(%rbp),%rsi
imul   $0xf,%rax,%rax
add    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    129b <main+0x14b>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     131e <main+0x1ce>
movslq -0x10(%rbp),%rax
lea    -0x4a3b0(%rbp),%rdi
imul   $0xf,%rax,%rax
add    %rax,%rdi
call   1050 <puts@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12ed <main+0x19d>
jmp    1323 <main+0x1d3>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1186 <main+0x36>
mov    $0x0,%al
call   1060 <getchar@plt>
xor    %eax,%eax
add    $0x4a3b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4a398,%rsp
lea    0xe98(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    12b9 <main+0x169>
lea    0xe7a(%rip),%r15
lea    0xe76(%rip),%r13
lea    0xfb0(%rsp),%r12
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
test   %r14d,%r14d
je     11af <main+0x5f>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
je     11ec <main+0x9c>
lea    0x14(%rsp),%rbx
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
add    $0x4,%rbx
cmp    $0xa,%al
jne    11d0 <main+0x80>
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    $0x1,%ebp
cmp    $0xa,%al
je     123f <main+0xef>
mov    $0x1,%ebp
lea    0xfbf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
add    $0xf,%rbx
add    $0x1,%ebp
cmp    $0xa,%al
jne    1220 <main+0xd0>
cmp    $0x2,%ebp
mov    $0x1,%eax
cmovb  %eax,%ebp
mov    %r12,%rbx
xor    %r12d,%r12d
movslq 0x10(%rsp,%r12,4),%rax
lea    (%rax,%rax,4),%rax
lea    (%rax,%rax,2),%rax
lea    (%rsp,%rax,1),%rdi
add    $0x259a0,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
add    $0x1,%r12
add    $0xf,%rbx
cmp    %r12,%rbp
jne    1250 <main+0x100>
add    $0x1,%ebp
add    $0xffffffffffffffff,%rbp
lea    0x259af(%rsp),%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <puts@plt>
add    $0xf,%rbx
add    $0xffffffffffffffff,%rbp
jne    1290 <main+0x140>
add    $0x1,%r14d
cmp    0xc(%rsp),%r14d
lea    0xfb0(%rsp),%r12
jl     11a0 <main+0x50>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
add    $0x4a398,%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"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [1000 x i32]
%7 = alloca i64
%8 = alloca i8
%9 = alloca [10000 x [15 x i8]]
%10 = alloca [10000 x [15 x i8]]
store i32 0, i32* %1
store i64 10000, i64* %7
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
store i32 0, i32* %3
br label %12
12: ; preds = %91, %0
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %94
16: ; preds = %12
store i32 0, i32* %5
%17 = load i32, i32* %3
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @putchar(i8 signext 10)
br label %21
21: ; preds = %19, %16
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %24
%26 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %25)
br label %27
27: ; preds = %31, %21
%28 = call signext i8 (...) @getchar()
store i8 %28, i8* %8
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 10
br i1 %30, label %31, label %37
31: ; preds = %27
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %34
%36 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %35)
br label %27
37: ; preds = %27
store i32 0, i32* %5
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds [10000 x [15 x i8]], [10000 x [15 x i8]]* %9, i64 0, i64 %40
%42 = getelementptr inbounds [15 x i8], [15 x i8]* %41, i64 0, i64 0
%43 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %48, %37
%45 = call signext i8 (...) @getchar()
store i8 %45, i8* %8
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 10
br i1 %47, label %48, label %55
48: ; preds = %44
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds [10000 x [15 x i8]], [10000 x [15 x i8]]* %9, i64 0, i64 %51
%53 = getelementptr inbounds [15 x i8], [15 x i8]* %52, i64 0, i64 0
%54 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %53)
br label %44
55: ; preds = %44
store i32 0, i32* %4
br label %56
56: ; preds = %73, %55
%57 = load i32, i32* %4
%58 = load i32, i32* %5
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %76
60: ; preds = %56
%61 = load i32, i32* %4
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [1000 x i32], [1000 x i32]* %6, i64 0, i64 %62
%64 = load i32, i32* %63
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [10000 x [15 x i8]], [10000 x [15 x i8]]* %10, i64 0, i64 %65
%67 = getelementptr inbounds [15 x i8], [15 x i8]* %66, i64 0, i64 0
%68 = load i32, i32* %4
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [10000 x [15 x i8]], [10000 x [15 x i8]]* %9, i64 0, i64 %69
%71 = getelementptr inbounds [15 x i8], [15 x i8]* %70, i64 0, i64 0
%72 = call i32 @strcpy(i8* %67, i8* %71)
br label %73
73: ; preds = %60
%74 = load i32, i32* %4
%75 = add nsw i32 %74, 1
store i32 %75, i32* %4
br label %56
76: ; preds = %56
store i32 1, i32* %4
br label %77
77: ; preds = %87, %76
%78 = load i32, i32* %4
%79 = load i32, i32* %5
%80 = icmp sle i32 %78, %79
br i1 %80, label %81, label %90
81: ; preds = %77
%82 = load i32, i32* %4
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [10000 x [15 x i8]], [10000 x [15 x i8]]* %10, i64 0, i64 %83
%85 = getelementptr inbounds [15 x i8], [15 x i8]* %84, i64 0, i64 0
%86 = call i32 @puts(i8* %85)
br label %87
87: ; preds = %81
%88 = load i32, i32* %4
%89 = add nsw i32 %88, 1
store i32 %89, i32* %4
br label %77
90: ; preds = %77
br label %91
91: ; preds = %90
%92 = load i32, i32* %3
%93 = add nsw i32 %92, 1
store i32 %93, i32* %3
br label %12
94: ; preds = %12
%95 = call signext i8 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i32]
%3 = alloca [10000 x [15 x i8]]
%4 = alloca [10000 x [15 x i8]]
%5 = bitcast i32* %1 to i8*
%6 = bitcast [1000 x i32]* %2 to i8*
%7 = getelementptr inbounds [10000 x [15 x i8]], [10000 x [15 x i8]]* %3, i64 0, i64 0, i64 0
%8 = getelementptr inbounds [10000 x [15 x i8]], [10000 x [15 x i8]]* %4, i64 0, i64 0, i64 0
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 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 %70
12: ; preds = %0
%13 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 0
br label %14
14: ; preds = %12, %66
%15 = phi i32 [ 0, %12 ], [ %67, %66 ]
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 @putchar(i8 signext 10)
br label %19
19: ; preds = %17, %14
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %13)
%21 = call signext i8 (...) @getchar()
%22 = icmp eq i8 %21, 10
br i1 %22, label %30, label %23
23: ; preds = %19, %23
%24 = phi i64 [ %25, %23 ], [ 1, %19 ]
%25 = add nuw i64 %24, 1
%26 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %24
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %26)
%28 = call signext i8 (...) @getchar()
%29 = icmp eq i8 %28, 10
br i1 %29, label %30, label %23
30: ; preds = %23, %19
%31 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%32 = call signext i8 (...) @getchar()
%33 = icmp eq i8 %32, 10
br i1 %33, label %36, label %40
34: ; preds = %40
%35 = trunc i64 %42 to i32
br label %36
36: ; preds = %34, %30
%37 = phi i32 [ 1, %30 ], [ %35, %34 ]
%38 = call i32 @llvm.umax.i32(i32 %37, i32 1)
%39 = zext i32 %38 to i64
br label %47
40: ; preds = %30, %40
%41 = phi i64 [ %42, %40 ], [ 1, %30 ]
%42 = add nuw i64 %41, 1
%43 = getelementptr inbounds [10000 x [15 x i8]], [10000 x [15 x i8]]* %3, i64 0, i64 %41, i64 0
%44 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %43)
%45 = call signext i8 (...) @getchar()
%46 = icmp eq i8 %45, 10
br i1 %46, label %34, label %40
47: ; preds = %36, %47
%48 = phi i64 [ 0, %36 ], [ %55, %47 ]
%49 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [10000 x [15 x i8]], [10000 x [15 x i8]]* %4, i64 0, i64 %51, i64 0
%53 = getelementptr inbounds [10000 x [15 x i8]], [10000 x [15 x i8]]* %3, i64 0, i64 %48, i64 0
%54 = call i32 @strcpy(i8* %52, i8* %53)
%55 = add nuw nsw i64 %48, 1
%56 = icmp eq i64 %55, %39
br i1 %56, label %57, label %47
57: ; preds = %47
%58 = add i32 %38, 1
%59 = zext i32 %58 to i64
br label %60
60: ; preds = %57, %60
%61 = phi i64 [ 1, %57 ], [ %64, %60 ]
%62 = getelementptr inbounds [10000 x [15 x i8]], [10000 x [15 x i8]]* %4, i64 0, i64 %61, i64 0
%63 = call i32 @puts(i8* %62)
%64 = add nuw nsw i64 %61, 1
%65 = icmp eq i64 %64, %59
br i1 %65, label %66, label %60
66: ; preds = %60
%67 = add nuw nsw i32 %15, 1
%68 = load i32, i32* %1
%69 = icmp slt i32 %67, %68
br i1 %69, label %14, label %70
70: ; preds = %66, %0
%71 = call signext i8 (...) @getchar()
ret i32 0
}