#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*/ printf(char *, ...);
scalar_t__ scanf(char *, ...);
int /*<<< orphan*/ sort(int *, int /*<<< orphan*/, int, char **);
int main(void) {
  int i, j, n, k, index[1000];
  char c, x[10001][80];
  scanf("%d\n", &n);
  while (n-- > 0) {
    i = 0;
    while (scanf("%d", &index[i++]) && getchar() != '\n')
      ;
    for (k = 0; k < i; k++)
      scanf("%s ", x[k]);
    sort(index, 0, i - 1, x);
    for (k = 0; k < i; k++)
      printf("%s\n", x[k]);
    if (n != 0)
      printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc4530,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
cmp    $0x0,%eax
jle    12a5 <main+0x165>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
lea    -0xfc0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0xc4521(%rbp)
je     11d3 <main+0x93>
mov    $0x0,%al
call   1050 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0xc4521(%rbp)
mov    -0xc4521(%rbp),%al
test   $0x1,%al
jne    11e6 <main+0xa6>
jmp    11eb <main+0xab>
jmp    117f <main+0x3f>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    122c <main+0xec>
movslq -0x14(%rbp),%rax
lea    -0xc4520(%rbp),%rsi
imul   $0x50,%rax,%rax
add    %rax,%rsi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f2 <main+0xb2>
lea    -0xfc0(%rbp),%rdi
mov    -0x8(%rbp),%edx
sub    $0x1,%edx
lea    -0xc4520(%rbp),%rcx
xor    %esi,%esi
call   1040 <sort@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1288 <main+0x148>
movslq -0x14(%rbp),%rax
lea    -0xc4520(%rbp),%rsi
imul   $0x50,%rax,%rax
add    %rax,%rsi
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    124e <main+0x10e>
cmpl   $0x0,-0x10(%rbp)
je     12a0 <main+0x160>
lea    0xd69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1164 <main+0x24>
xor    %eax,%eax
add    $0xc4530,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc4508,%rsp
lea    0xe98(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
test   %eax,%eax
jle    124b <main+0xfb>
lea    0xfb0(%rsp),%r15
lea    0xe71(%rip),%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %rbp,%r13
lea    (%rsp,%rbp,4),%rsi
add    $0x10,%rsi
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   1070 <scanf@plt>
test   %rax,%rax
je     11cd <main+0x7d>
lea    0x1(%r13),%rbp
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
jne    11a0 <main+0x50>
lea    0x1(%r13),%r14d
mov    %r14,%r12
mov    %r15,%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <scanf@plt>
add    $0x50,%rbp
add    $0xffffffffffffffff,%r12
jne    11e0 <main+0x90>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    %r13d,%edx
mov    %r15,%rcx
call   1050 <sort@plt>
mov    %r15,%rbp
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1040 <puts@plt>
add    $0x50,%rbp
add    $0xffffffffffffffff,%r14
jne    1210 <main+0xc0>
cmpl   $0x0,0xc(%rsp)
je     124b <main+0xfb>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,0xc(%rsp)
mov    $0x0,%ebp
test   %eax,%eax
jg     11a0 <main+0x50>
xor    %eax,%eax
add    $0xc4508,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%s \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i32]
%3 = alloca [10001 x [80 x i8]]
%4 = bitcast i32* %1 to i8*
%5 = bitcast [1000 x i32]* %2 to i8*
%6 = getelementptr inbounds [10001 x [80 x i8]], [10001 x [80 x i8]]* %3, i64 0, i64 0, i64 0
%7 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = add nsw i32 %8, -1
store i32 %9, i32* %1
%10 = icmp sgt i32 %8, 0
br i1 %10, label %11, label %51
11: ; preds = %0
%12 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 0
%13 = bitcast [10001 x [80 x i8]]* %3 to i8**
br label %14
14: ; preds = %23, %11
%15 = phi i64 [ 0, %11 ], [ %24, %23 ]
%16 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 %15
%17 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %14
%20 = add nuw i64 %15, 1
%21 = call signext i8 (...) @getchar()
%22 = icmp eq i8 %21, 10
br i1 %22, label %25, label %23
23: ; preds = %19, %46
%24 = phi i64 [ %20, %19 ], [ 0, %46 ]
br label %14
25: ; preds = %14, %19
%26 = trunc i64 %15 to i32
%27 = add i64 %15, 1
%28 = and i64 %27, 4294967295
br label %29
29: ; preds = %25, %29
%30 = phi i64 [ 0, %25 ], [ %33, %29 ]
%31 = getelementptr inbounds [10001 x [80 x i8]], [10001 x [80 x i8]]* %3, i64 0, i64 %30, i64 0
%32 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%33 = add nuw nsw i64 %30, 1
%34 = icmp eq i64 %33, %28
br i1 %34, label %35, label %29
35: ; preds = %29
%36 = call i32 @sort(i32* %12, i32 0, i32 %26, i8** %13)
br label %37
37: ; preds = %35, %37
%38 = phi i64 [ 0, %35 ], [ %41, %37 ]
%39 = getelementptr inbounds [10001 x [80 x i8]], [10001 x [80 x i8]]* %3, i64 0, i64 %38, i64 0
%40 = call i32 @puts(i8* %39)
%41 = add nuw nsw i64 %38, 1
%42 = icmp eq i64 %41, %28
br i1 %42, label %43, label %37
43: ; preds = %37
%44 = load i32, i32* %1
%45 = icmp eq i32 %44, 0
br i1 %45, label %51, label %46
46: ; preds = %43
%47 = call i32 @putchar(i32 10)
%48 = load i32, i32* %1
%49 = add nsw i32 %48, -1
store i32 %49, i32* %1
%50 = icmp sgt i32 %48, 0
br i1 %50, label %23, label %51
51: ; preds = %46, %43, %0
ret i32 0
}