a=[]

for i in eval(input()):

    if i=="S":

        a+=i

    

    if a:

        if i=="T" and a[-1]=="T":

            a+=i

        if i=="T" and a[-1]=="S":

            a.pop(-1)

    elif i=="T" and len(a)==0:

        a+=i    

print((len(a)))
s=t=0

for i in eval(input()):

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

  else:

    if s:s-=1

    else:t+=1

print((s+t))
a = []
for i in eval(input()):
    if i == "S":
        a += i
    if a:
        if i == "T" and a[-1] == "T":
            a += i
        if i == "T" and a[-1] == "S":
            a.pop(-1)
    elif i == "T" and len(a) == 0:
        a += i
print((len(a)))

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

-a = [] +s = t = 0 -        a += i -    if a: -        if i == "T" and a[-1] == "T": -            a += i -        if i == "T" and a[-1] == "S": -            a.pop(-1) -    elif i == "T" and len(a) == 0: -        a += i -print((len(a))) +        s += 1 +    else: +        if s: +            s -= 1 +        else: +            t += 1 +print((s + t))