x=eval(input());a,l=0,len(x)

for i in range(l):

  if x[l-i-1]=="T":a+=1

  else:a=max(0,a-1)

print((a*2))
x=eval(input())

s=t=0

for i in x:

  if i=="S":s+=1

  else:

    if s:

      s-=1

    else:

      t+=1

print((s+t))
x = eval(input())
a, l = 0, len(x)
for i in range(l):
    if x[l - i - 1] == "T":
        a += 1
    else:
        a = max(0, a - 1)
print((a * 2))

x = eval(input())
s = t = 0
for i in x:
    if i == "S":
        s += 1
    else:
        if s:
            s -= 1
        else:
            t += 1
print((s + t))

-a, l = 0, len(x) -for i in range(l): -    if x[l - i - 1] == "T": -        a += 1 +s = t = 0 +for i in x: +    if i == "S": +        s += 1 -        a = max(0, a - 1) -print((a * 2)) +        if s: +            s -= 1 +        else: +            t += 1 +print((s + t))