#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 *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int main() {
  int n, i, p, q;
  char a[105][105], x[105], y[105];
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%s", a[i]);
  scanf("%d", &n);
  while (n--) {
    scanf("%s%s", x, y);
    for (p = 0;; p++)
      if (!strcmp(x, a[p]))
        break;
    for (q = 0;; q++)
      if (!strcmp(y, a[q]))
        break;
    if (p > q)
      for (i = p; i > q; i--)
        printf("%s ", a[i]);
    else if (p < q)
      for (i = p; i < q; i++)
        printf("%s ", a[i]);
    puts(y);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2c10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a5 <main+0x65>
movslq -0xc(%rbp),%rax
lea    -0x2b30(%rbp),%rsi
imul   $0x69,%rax,%rax
add    %rax,%rsi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116b <main+0x2b>
lea    0xe54(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1327 <main+0x1e7>
lea    -0x2ba0(%rbp),%rsi
lea    -0x2c10(%rbp),%rdx
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
movl   $0x0,-0x10(%rbp)
lea    -0x2ba0(%rbp),%rdi
movslq -0x10(%rbp),%rax
lea    -0x2b30(%rbp),%rsi
imul   $0x69,%rax,%rax
add    %rax,%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    121a <main+0xda>
jmp    122d <main+0xed>
jmp    121f <main+0xdf>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11ee <main+0xae>
movl   $0x0,-0x14(%rbp)
lea    -0x2c10(%rbp),%rdi
movslq -0x14(%rbp),%rax
lea    -0x2b30(%rbp),%rsi
imul   $0x69,%rax,%rax
add    %rax,%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1260 <main+0x120>
jmp    1273 <main+0x133>
jmp    1265 <main+0x125>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1234 <main+0xf4>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    12c2 <main+0x182>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    12bd <main+0x17d>
movslq -0xc(%rbp),%rax
lea    -0x2b30(%rbp),%rsi
imul   $0x69,%rax,%rax
add    %rax,%rsi
lea    0xd5e(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1285 <main+0x145>
jmp    1316 <main+0x1d6>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1311 <main+0x1d1>
mov    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    130c <main+0x1cc>
movslq -0xc(%rbp),%rax
lea    -0x2b30(%rbp),%rsi
imul   $0x69,%rax,%rax
add    %rax,%rsi
lea    0xd0f(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12d4 <main+0x194>
jmp    1311 <main+0x1d1>
jmp    1316 <main+0x1d6>
lea    -0x2c10(%rbp),%rdi
call   1030 <puts@plt>
jmp    11b7 <main+0x77>
xor    %eax,%eax
add    $0x2c10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2c08,%rsp
lea    0xea8(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    119f <main+0x5f>
lea    0xf0(%rsp),%rbx
lea    0xe8b(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rax
add    $0x69,%rbx
cmp    %rax,%rbp
jl     1180 <main+0x40>
lea    0xe5a(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
subl   $0x1,0x4(%rsp)
jae    11cd <main+0x8d>
xor    %eax,%eax
add    $0x2c08,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movabs $0xffffffff00000000,%rbp
ff ff ff
movabs $0x100000000,%r12
lea    0x80(%rsp),%r15
lea    0x10(%rsp),%rbx
jmp    120e <main+0xce>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
subl   $0x1,0x4(%rsp)
movabs $0xffffffff00000000,%rbp
ff ff ff
jb     11b9 <main+0x79>
xor    %r14d,%r14d
lea    0xdeb(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %r15,%r13
mov    $0xffffffffffffffff,%r15
lea    0xf0(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
mov    %r14,%rcx
add    %r12,%rbp
add    $0x1,%r15
add    $0x69,%rbx
add    $0x1,%r14d
test   %eax,%eax
jne    1240 <main+0x100>
mov    %rcx,%rax
mov    %rcx,0x8(%rsp)
neg    %ecx
mov    $0xffffffff,%r12d
lea    0xf0(%rsp),%rbx
movabs $0xffffffff00000000,%r13
ff ff ff
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ecx,%r14d
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
movabs $0x100000000,%rcx
add    %rcx,%r13
add    $0x1,%r12d
add    $0x69,%rbx
lea    0x1(%r14),%ecx
test   %eax,%eax
jne    1290 <main+0x150>
movabs $0x100000000,%rcx
cmp    %r12d,%r15d
jbe    1320 <main+0x1e0>
sar    $0x20,%rbp
sar    $0x20,%r13
movslq 0x8(%rsp),%rax
imul   $0x69,%rax,%rax
lea    (%rsp,%rax,1),%rbx
add    $0xf0,%rbx
mov    %rcx,%r12
lea    0x80(%rsp),%r15
lea    0xd0e(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbp
add    $0xffffffffffffff97,%rbx
cmp    %r13,%rbp
jg     1300 <main+0x1c0>
jmp    11f0 <main+0xb0>
nopl   (%rax)
cmp    %r12d,%r15d
mov    %rcx,%r12
lea    0x80(%rsp),%r15
lea    0xcd3(%rip),%rbp
jae    11f0 <main+0xb0>
mov    0x8(%rsp),%eax
imul   $0x69,%rax,%rax
lea    (%rsp,%rax,1),%rbx
add    $0xf0,%rbx
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
add    $0x69,%rbx
add    $0xffffffff,%r14d
jne    1350 <main+0x210>
jmp    11f0 <main+0xb0>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"%s%s\00"
@.str.3 = [4 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 [105 x [105 x i8]]
%7 = alloca [105 x i8]
%8 = alloca [105 x i8]
store i32 0, i32* %1
%9 = 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 %10
10: ; preds = %20, %0
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [105 x [105 x i8]], [105 x [105 x i8]]* %6, i64 0, i64 %16
%18 = getelementptr inbounds [105 x i8], [105 x i8]* %17, i64 0, i64 0
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %14
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %10
23: ; preds = %10
%24 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %25
25: ; preds = %101, %23
%26 = load i32, i32* %2
%27 = add nsw i32 %26, -1
store i32 %27, i32* %2
%28 = icmp ne i32 %26, 0
br i1 %28, label %29, label %104
29: ; preds = %25
%30 = getelementptr inbounds [105 x i8], [105 x i8]* %7, i64 0, i64 0
%31 = getelementptr inbounds [105 x i8], [105 x i8]* %8, i64 0, i64 0
%32 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %30, i8* %31)
store i32 0, i32* %4
br label %33
33: ; preds = %43, %29
%34 = getelementptr inbounds [105 x i8], [105 x i8]* %7, i64 0, i64 0
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [105 x [105 x i8]], [105 x [105 x i8]]* %6, i64 0, i64 %36
%38 = getelementptr inbounds [105 x i8], [105 x i8]* %37, i64 0, i64 0
%39 = call i32 @strcmp(i8* %34, i8* %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %42, label %41
41: ; preds = %33
br label %46
42: ; preds = %33
br label %43
43: ; preds = %42
%44 = load i32, i32* %4
%45 = add nsw i32 %44, 1
store i32 %45, i32* %4
br label %33
46: ; preds = %41
store i32 0, i32* %5
br label %47
47: ; preds = %57, %46
%48 = getelementptr inbounds [105 x i8], [105 x i8]* %8, i64 0, i64 0
%49 = load i32, i32* %5
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [105 x [105 x i8]], [105 x [105 x i8]]* %6, i64 0, i64 %50
%52 = getelementptr inbounds [105 x i8], [105 x i8]* %51, i64 0, i64 0
%53 = call i32 @strcmp(i8* %48, i8* %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %56, label %55
55: ; preds = %47
br label %60
56: ; preds = %47
br label %57
57: ; preds = %56
%58 = load i32, i32* %5
%59 = add nsw i32 %58, 1
store i32 %59, i32* %5
br label %47
60: ; preds = %55
%61 = load i32, i32* %4
%62 = load i32, i32* %5
%63 = icmp sgt i32 %61, %62
br i1 %63, label %64, label %80
64: ; preds = %60
%65 = load i32, i32* %4
store i32 %65, i32* %3
br label %66
66: ; preds = %76, %64
%67 = load i32, i32* %3
%68 = load i32, i32* %5
%69 = icmp sgt i32 %67, %68
br i1 %69, label %70, label %79
70: ; preds = %66
%71 = load i32, i32* %3
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [105 x [105 x i8]], [105 x [105 x i8]]* %6, i64 0, i64 %72
%74 = getelementptr inbounds [105 x i8], [105 x i8]* %73, i64 0, i64 0
%75 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %70
%77 = load i32, i32* %3
%78 = add nsw i32 %77, -1
store i32 %78, i32* %3
br label %66
79: ; preds = %66
br label %101
80: ; preds = %60
%81 = load i32, i32* %4
%82 = load i32, i32* %5
%83 = icmp slt i32 %81, %82
br i1 %83, label %84, label %100
84: ; preds = %80
%85 = load i32, i32* %4
store i32 %85, i32* %3
br label %86
86: ; preds = %96, %84
%87 = load i32, i32* %3
%88 = load i32, i32* %5
%89 = icmp slt i32 %87, %88
br i1 %89, label %90, label %99
90: ; preds = %86
%91 = load i32, i32* %3
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds [105 x [105 x i8]], [105 x [105 x i8]]* %6, i64 0, i64 %92
%94 = getelementptr inbounds [105 x i8], [105 x i8]* %93, i64 0, i64 0
%95 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %94)
br label %96
96: ; preds = %90
%97 = load i32, i32* %3
%98 = add nsw i32 %97, 1
store i32 %98, i32* %3
br label %86
99: ; preds = %86
br label %100
100: ; preds = %99, %80
br label %101
101: ; preds = %100, %79
%102 = getelementptr inbounds [105 x i8], [105 x i8]* %8, i64 0, i64 0
%103 = call i32 @puts(i8* %102)
br label %25
104: ; preds = %25
ret i32 0
}

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