n=eval(input())

a=input()

count=0

for r in range(n):

	b=input()

	lb=len(b)

	flag=0

	for s in range(lb):

		for i in range(lb-(s+1)*(len(a)-1)):

			if b[i:i+(s+1)*len(a):s+1]==a:

				count+=1

				flag=1

				break

		if flag==1:break

print(count)

	
n=eval(input())

a=input()

la=len(a)

count=0

for r in range(n):

	b=input()

	lb=len(b)

	flag=0

	for skip in range(lb):

		for ini in range(lb-(skip+1)*(la-1)):

			if b[ini:ini+(skip+1)*la:skip+1]==a:

				count+=1

				flag=1

				break

		if flag==1:break

print(count)

	
n = eval(input())
a = input()
count = 0
for r in range(n):
    b = input()
    lb = len(b)
    flag = 0
    for s in range(lb):
        for i in range(lb - (s + 1) * (len(a) - 1)):
            if b[i : i + (s + 1) * len(a) : s + 1] == a:
                count += 1
                flag = 1
                break
        if flag == 1:
            break
print(count)

n = eval(input())
a = input()
la = len(a)
count = 0
for r in range(n):
    b = input()
    lb = len(b)
    flag = 0
    for skip in range(lb):
        for ini in range(lb - (skip + 1) * (la - 1)):
            if b[ini : ini + (skip + 1) * la : skip + 1] == a:
                count += 1
                flag = 1
                break
        if flag == 1:
            break
print(count)

+la = len(a) -    for s in range(lb): -        for i in range(lb - (s + 1) * (len(a) - 1)): -            if b[i : i + (s + 1) * len(a) : s + 1] == a: +    for skip in range(lb): +        for ini in range(lb - (skip + 1) * (la - 1)): +            if b[ini : ini + (skip + 1) * la : skip + 1] == a: