#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, ...);
scalar_t__ strcmp(char *, char *);
int main() {
  int i, n, q;
  scanf("%d", &n);
  char *arr[n];
  char *query;
  query = (char *)malloc(21 * sizeof(char));
  for (i = 0; i < n; i++) {
    arr[i] = (char *)malloc(21 * sizeof(char));
  }
  for (i = 0; i < n; i++) {
    scanf("%s", arr[i]);
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%s", query);
    int j;
    int count = 0;
    for (j = 0; j < n; j++) {
      if (strcmp(query, arr[j]) == 0) {
        count++;
      }
    }
    printf("%d\n", count);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    $0x15,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d0 <main+0x90>
mov    $0x15,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119d <main+0x5d>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120b <main+0xcb>
mov    -0x38(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11d7 <main+0x97>
lea    0xdee(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12b4 <main+0x174>
mov    -0x28(%rbp),%rsi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1297 <main+0x157>
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rdi
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1284 <main+0x144>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1289 <main+0x149>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1250 <main+0x110>
mov    -0x30(%rbp),%esi
lea    0xd65(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1224 <main+0xe4>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%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    $0x18,%rsp
lea    0xea8(%rip),%rdi
lea    -0x2c(%rbp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %rsp,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%r13
lea    0xf(,%rax,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    $0x15,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
cmpl   $0x0,-0x2c(%rbp)
jle    11ec <main+0xac>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x15,%edi
call   1050 <malloc@plt>
mov    %rax,0x0(%r13,%rbx,8)
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     11a0 <main+0x60>
test   %eax,%eax
jle    11ec <main+0xac>
lea    0xe3c(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    0x0(%r13,%rbx,8),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     11d0 <main+0x90>
lea    0xe0d(%rip),%rdi
xor    %r14d,%r14d
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,-0x30(%rbp)
jg     1238 <main+0xf8>
mov    -0x38(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
nopl   0x0(%rax)
lea    0xddf(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x1,%r14d
cmp    -0x30(%rbp),%r14d
jge    1207 <main+0xc7>
xor    %ebx,%ebx
lea    0xdc2(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    1220 <main+0xe0>
xor    %r15d,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13,%r15,8),%rsi
mov    %r12,%rdi
call   1040 <strcmp@plt>
cmp    $0x1,%rax
adc    $0x0,%ebx
add    $0x1,%r15
movslq -0x2c(%rbp),%rax
cmp    %rax,%r15
jl     1260 <main+0x120>
jmp    1220 <main+0xe0>

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

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