x=list(eval(input()))

stack=[]

for i in range(len(x)):

    if x[i]=="S":

        stack.append(x[i])

    elif x[i]=="T":

        if len(stack)==0:

            stack.append(x[i])

        elif stack[-1]=="T":

            stack.append(x[i])

        elif stack[-1]=="S":

            stack.pop()

print((len(stack)))

x=list(eval(input()))

stack=[]

t_f=[]

for i in range(len(x)):

    if x[i]=="S":

        stack.append(x[i])

    elif x[i]=="T":

        if len(stack)!=0:

            stack.pop()

        else:

            t_f.append(x[i])

print((len(stack)+len(t_f)))



x = list(eval(input()))
stack = []
for i in range(len(x)):
    if x[i] == "S":
        stack.append(x[i])
    elif x[i] == "T":
        if len(stack) == 0:
            stack.append(x[i])
        elif stack[-1] == "T":
            stack.append(x[i])
        elif stack[-1] == "S":
            stack.pop()
print((len(stack)))

x = list(eval(input()))
stack = []
t_f = []
for i in range(len(x)):
    if x[i] == "S":
        stack.append(x[i])
    elif x[i] == "T":
        if len(stack) != 0:
            stack.pop()
        else:
            t_f.append(x[i])
print((len(stack) + len(t_f)))

+t_f = [] -        if len(stack) == 0: -            stack.append(x[i]) -        elif stack[-1] == "T": -            stack.append(x[i]) -        elif stack[-1] == "S": +        if len(stack) != 0: -print((len(stack))) +        else: +            t_f.append(x[i]) +print((len(stack) + len(t_f)))