x=eval(input())

l=len(x)

f=0

c=0

for i in range(l):

    if x[i]=="S":

        f+=1

    else:

        if f==0:

            c+=1

        else:

            f-=1

print((2*c))

x=eval(input())

f=0

c=0

#なかなか良い解法、flag立てる

for i in x:

    if i=="S":

        f+=1

    else:

        if f==0:

            c+=1

        else:

            f-=1

print((2*c))

x = eval(input())
l = len(x)
f = 0
c = 0
for i in range(l):
    if x[i] == "S":
        f += 1
    else:
        if f == 0:
            c += 1
        else:
            f -= 1
print((2 * c))

x = eval(input())
f = 0
c = 0
# なかなか良い解法、flag立てる
for i in x:
    if i == "S":
        f += 1
    else:
        if f == 0:
            c += 1
        else:
            f -= 1
print((2 * c))

-l = len(x) -for i in range(l): -    if x[i] == "S": +# なかなか良い解法、flag立てる +for i in x: +    if i == "S":