x = list(map(str, input().rstrip()))



stock = 0

rest = 0

for i in x:

    if i == "S":

        stock += 1

    elif i == "T" and stock >= 1:

        stock -= 1

    else:

        rest += 1



print((stock + rest))
x = eval(input())



stock = 0

rest = len(x)



for a in x:

    if a == "S":

        stock += 1

    else:

        if stock > 0:

            stock -= 1

            rest -= 2

        else:

            stock = 0



print(rest)
x = list(map(str, input().rstrip()))
stock = 0
rest = 0
for i in x:
    if i == "S":
        stock += 1
    elif i == "T" and stock >= 1:
        stock -= 1
    else:
        rest += 1
print((stock + rest))

x = eval(input())
stock = 0
rest = len(x)
for a in x:
    if a == "S":
        stock += 1
    else:
        if stock > 0:
            stock -= 1
            rest -= 2
        else:
            stock = 0
print(rest)

-x = list(map(str, input().rstrip())) +x = eval(input()) -rest = 0 -for i in x: -    if i == "S": +rest = len(x) +for a in x: +    if a == "S": -    elif i == "T" and stock >= 1: -        stock -= 1 -        rest += 1 -print((stock + rest)) +        if stock > 0: +            stock -= 1 +            rest -= 2 +        else: +            stock = 0 +print(rest)