#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 ****get_document(char *);
char *get_input_text();
char ***kth_paragraph(char ****, int);
char **kth_sentence_in_mth_paragraph(char ****, int, int);
char *kth_word_in_mth_sentence_of_nth_paragraph(char ****, int, int, int);
int /*<<< orphan*/ print_paragraph(char ***);
int /*<<< orphan*/ print_sentence(char **);
int /*<<< orphan*/ print_word(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  char *text = get_input_text();
  char ****document = get_document(text);
  int q;
  scanf("%d", &q);
  while (q--) {
    int type;
    scanf("%d", &type);
    if (type == 3) {
      int k, m, n;
      scanf("%d %d %d", &k, &m, &n);
      char *word = kth_word_in_mth_sentence_of_nth_paragraph(document, k, m, n);
      print_word(word);
    } else if (type == 2) {
      int k, m;
      scanf("%d %d", &k, &m);
      char **sentence = kth_sentence_in_mth_paragraph(document, k, m);
      print_sentence(sentence);
    } else {
      int k;
      scanf("%d", &k);
      char ***paragraph = kth_paragraph(document, k);
      print_paragraph(paragraph);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <get_input_text@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <get_document@plt>
mov    %rax,-0x18(%rbp)
lea    0xe38(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
cmp    $0x0,%eax
je     12c9 <main+0x129>
lea    0xe12(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
cmpl   $0x3,-0x20(%rbp)
jne    1247 <main+0xa7>
lea    0xdf0(%rip),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
call   10a0 <kth_word_in_mth_sentence_of_nth_paragraph@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <print_word@plt>
jmp    12b8 <main+0x118>
cmpl   $0x2,-0x20(%rbp)
jne    1288 <main+0xe8>
lea    0xdab(%rip),%rdi
lea    -0x3c(%rbp),%rsi
lea    -0x40(%rbp),%rdx
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x40(%rbp),%edx
call   10c0 <kth_sentence_in_mth_paragraph@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1090 <print_sentence@plt>
jmp    12b3 <main+0x113>
lea    0xd77(%rip),%rdi
lea    -0x4c(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x4c(%rbp),%esi
call   1030 <kth_paragraph@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
call   10b0 <print_paragraph@plt>
jmp    12b8 <main+0x118>
lea    0xd4a(%rip),%rdi
call   1050 <printf@plt>
jmp    11d9 <main+0x39>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1070 <get_input_text@plt>
mov    %rax,%rdi
call   1060 <get_document@plt>
mov    %rax,%rbx
lea    0xe3f(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    11eb <main+0x4b>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe14(%rip),%r14
lea    0x14(%rsp),%r15
lea    0x4(%rsp),%r13
lea    0x8(%rsp),%rbp
lea    0x10(%rsp),%r12
jmp    1242 <main+0xa2>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1040 <kth_paragraph@plt>
mov    %rax,%rdi
call   10b0 <print_paragraph@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
subl   $0x1,0xc(%rsp)
jb     11da <main+0x3a>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x14(%rsp),%eax
cmp    $0x2,%eax
je     12a0 <main+0x100>
cmp    $0x3,%eax
jne    1210 <main+0x70>
lea    0xd9c(%rip),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x4(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0x10(%rsp),%ecx
mov    %rbx,%rdi
call   10a0 <kth_word_in_mth_sentence_of_nth_paragraph@plt>
mov    %rax,%rdi
call   1050 <print_word@plt>
jmp    1231 <main+0x91>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xd5c(%rip),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1080 <scanf@plt>
mov    0x4(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
call   10c0 <kth_sentence_in_mth_paragraph@plt>
mov    %rax,%rdi
call   1090 <print_sentence@plt>
jmp    1231 <main+0x91>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%d %d %d\00"
@.str.2 = [6 x i8] c"%d %d\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8****
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8**
%13 = alloca i32
%14 = alloca i8***
store i32 0, i32* %1
%15 = call i8* (...) @get_input_text()
store i8* %15, i8** %2
%16 = load i8*, i8** %2
%17 = call i8**** @get_document(i8* %16)
store i8**** %17, i8***** %3
%18 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
br label %19
19: ; preds = %55, %0
%20 = load i32, i32* %4
%21 = add nsw i32 %20, -1
store i32 %21, i32* %4
%22 = icmp ne i32 %20, 0
br i1 %22, label %23, label %57
23: ; preds = %19
%24 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%25 = load i32, i32* %5
%26 = icmp eq i32 %25, 3
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %6, i32* %7, i32* %8)
%29 = load i8****, i8***** %3
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = call i8* @kth_word_in_mth_sentence_of_nth_paragraph(i8**** %29, i32 %30, i32 %31, i32 %32)
store i8* %33, i8** %9
%34 = load i8*, i8** %9
%35 = call i32 @print_word(i8* %34)
br label %55
36: ; preds = %23
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, 2
br i1 %38, label %39, label %47
39: ; preds = %36
%40 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %10, i32* %11)
%41 = load i8****, i8***** %3
%42 = load i32, i32* %10
%43 = load i32, i32* %11
%44 = call i8** @kth_sentence_in_mth_paragraph(i8**** %41, i32 %42, i32 %43)
store i8** %44, i8*** %12
%45 = load i8**, i8*** %12
%46 = call i32 @print_sentence(i8** %45)
br label %54
47: ; preds = %36
%48 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %13)
%49 = load i8****, i8***** %3
%50 = load i32, i32* %13
%51 = call i8*** @kth_paragraph(i8**** %49, i32 %50)
store i8*** %51, i8**** %14
%52 = load i8***, i8**** %14
%53 = call i32 @print_paragraph(i8*** %52)
br label %54
54: ; preds = %47, %39
br label %55
55: ; preds = %54, %27
%56 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %19
57: ; preds = %19
%58 = load i32, i32* %1
ret i32 %58
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c"%d %d %d\00"
@.str.2 = [6 x i8] c"%d %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = tail call i8* (...) @get_input_text()
%10 = tail call i8**** @get_document(i8* %9)
%11 = bitcast i32* %1 to i8*
%12 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%13 = load i32, i32* %1
%14 = add nsw i32 %13, -1
store i32 %14, i32* %1
%15 = icmp eq i32 %13, 0
br i1 %15, label %50, label %16
16: ; preds = %0
%17 = bitcast i32* %2 to i8*
%18 = bitcast i32* %6 to i8*
%19 = bitcast i32* %7 to i8*
%20 = bitcast i32* %3 to i8*
%21 = bitcast i32* %4 to i8*
%22 = bitcast i32* %5 to i8*
%23 = bitcast i32* %8 to i8*
br label %24
24: ; preds = %16, %45
%25 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%26 = load i32, i32* %2
switch i32 %26, label %40 [
i32 3, label %27
i32 2, label %34
]
27: ; preds = %24
%28 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%29 = load i32, i32* %3
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = call i8* @kth_word_in_mth_sentence_of_nth_paragraph(i8**** %10, i32 %29, i32 %30, i32 %31)
%33 = call i32 @print_word(i8* %32)
br label %45
34: ; preds = %24
%35 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %6, i32* %7)
%36 = load i32, i32* %6
%37 = load i32, i32* %7
%38 = call i8** @kth_sentence_in_mth_paragraph(i8**** %10, i32 %36, i32 %37)
%39 = call i32 @print_sentence(i8** %38)
br label %45
40: ; preds = %24
%41 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%42 = load i32, i32* %8
%43 = call i8*** @kth_paragraph(i8**** %10, i32 %42)
%44 = call i32 @print_paragraph(i8*** %43)
br label %45
45: ; preds = %34, %40, %27
%46 = call i32 @putchar(i32 10)
%47 = load i32, i32* %1
%48 = add nsw i32 %47, -1
store i32 %48, i32* %1
%49 = icmp eq i32 %47, 0
br i1 %49, label %50, label %24
50: ; preds = %45, %0
ret i32 0
}