s = eval(input())

tt = 0

cnt = 0

for i in range(len(s)):

    if s[-i-1] == "T":

        tt += 1

    elif s[-i-1] == "S":

        t = min(1, tt)

        cnt += t

        tt -= t

print((len(s) - cnt * 2))

x = eval(input())

t = 0

c = 0

for i in range(len(x)):

    if x[-i-1] == "T":

        t += 1

    else:

        r = 1 if t > 0 else 0

        t -= r

        c += r

print((len(x) - c * 2))

s = eval(input())
tt = 0
cnt = 0
for i in range(len(s)):
    if s[-i - 1] == "T":
        tt += 1
    elif s[-i - 1] == "S":
        t = min(1, tt)
        cnt += t
        tt -= t
print((len(s) - cnt * 2))

x = eval(input())
t = 0
c = 0
for i in range(len(x)):
    if x[-i - 1] == "T":
        t += 1
    else:
        r = 1 if t > 0 else 0
        t -= r
        c += r
print((len(x) - c * 2))

-s = eval(input()) -tt = 0 -cnt = 0 -for i in range(len(s)): -    if s[-i - 1] == "T": -        tt += 1 -    elif s[-i - 1] == "S": -        t = min(1, tt) -        cnt += t -        tt -= t -print((len(s) - cnt * 2)) +x = eval(input()) +t = 0 +c = 0 +for i in range(len(x)): +    if x[-i - 1] == "T": +        t += 1 +    else: +        r = 1 if t > 0 else 0 +        t -= r +        c += r +print((len(x) - c * 2))