s = input()

score = 0

for u in range(eval(input())):

    ss = input()

    if len((ss+ss).split(s)) > 1:

        score += 1

print(score)
s = input()

score = 0

for u in range(eval(input())):

    ss = input()

    if s in ss*2:

        score += 1

print(score)
s = input()
score = 0
for u in range(eval(input())):
    ss = input()
    if len((ss + ss).split(s)) > 1:
        score += 1
print(score)

s = input()
score = 0
for u in range(eval(input())):
    ss = input()
    if s in ss * 2:
        score += 1
print(score)

-    if len((ss + ss).split(s)) > 1: +    if s in ss * 2: