target = eval(input())



count = 0

while True:

    line = eval(input())

    if line == 'END_OF_TEXT':

        break



    for word in line.split():

        if word.lower() == target.lower():

            count += 1



print(count)
W = eval(input())



count = 0

while True:

    line = eval(input())

    if line == 'END_OF_TEXT':

        break



    for s in line.lower().split():

        if s == W:

            count += 1



print(count)
target = eval(input())
count = 0
while True:
    line = eval(input())
    if line == "END_OF_TEXT":
        break
    for word in line.split():
        if word.lower() == target.lower():
            count += 1
print(count)

W = eval(input())
count = 0
while True:
    line = eval(input())
    if line == "END_OF_TEXT":
        break
    for s in line.lower().split():
        if s == W:
            count += 1
print(count)

-target = eval(input()) +W = eval(input()) -    for word in line.split(): -        if word.lower() == target.lower(): +    for s in line.lower().split(): +        if s == W: