n = eval(input())

s = input()

cnt = 0

for i in range(n):

    judge = False

    p = input()

    for k in range(len(p)):

        for j in range(1, len(p)):

            for l in range(len(s)):

                if k+l*j < len(p) and p[k+l*j] == s[l]:

                    if l+1 >= len(s): judge = True

                    continue

                break

    if judge == True: cnt += 1

print(cnt)
n = eval(input())

s = input()

cnt = 0

for i in range(n):

    judge = False

    p = input()

    for k in range(len(p)):

        if judge: break

        for j in range(1, len(p)):

            if judge: break

            for l in range(len(s)):

                if k+l*j < len(p) and p[k+l*j] == s[l]:

                    if l+1 >= len(s): judge = True

                    continue

                break

    if judge == True: cnt += 1

print(cnt)
n = eval(input())
s = input()
cnt = 0
for i in range(n):
    judge = False
    p = input()
    for k in range(len(p)):
        for j in range(1, len(p)):
            for l in range(len(s)):
                if k + l * j < len(p) and p[k + l * j] == s[l]:
                    if l + 1 >= len(s):
                        judge = True
                    continue
                break
    if judge == True:
        cnt += 1
print(cnt)

n = eval(input())
s = input()
cnt = 0
for i in range(n):
    judge = False
    p = input()
    for k in range(len(p)):
        if judge:
            break
        for j in range(1, len(p)):
            if judge:
                break
            for l in range(len(s)):
                if k + l * j < len(p) and p[k + l * j] == s[l]:
                    if l + 1 >= len(s):
                        judge = True
                    continue
                break
    if judge == True:
        cnt += 1
print(cnt)

+        if judge: +            break +            if judge: +                break