x = eval(input())



ans = 0

cnt = 0

for i in range(len(x)):

    if x[i] == 'S':

        cnt += 1

    elif x[i] == 'T':

        if cnt > 0:

            cnt -= 1

        else:

            ans += 2

print(ans)    
x = eval(input())



ans = 0

cnt_s = 0

for xx in x:

    if xx == 'T':

        if cnt_s > 0:

            cnt_s -= 1

        else:

            ans += 2

    else:

        cnt_s += 1

print(ans)

x = eval(input())
ans = 0
cnt = 0
for i in range(len(x)):
    if x[i] == "S":
        cnt += 1
    elif x[i] == "T":
        if cnt > 0:
            cnt -= 1
        else:
            ans += 2
print(ans)

x = eval(input())
ans = 0
cnt_s = 0
for xx in x:
    if xx == "T":
        if cnt_s > 0:
            cnt_s -= 1
        else:
            ans += 2
    else:
        cnt_s += 1
print(ans)

-cnt = 0 -for i in range(len(x)): -    if x[i] == "S": -        cnt += 1 -    elif x[i] == "T": -        if cnt > 0: -            cnt -= 1 +cnt_s = 0 +for xx in x: +    if xx == "T": +        if cnt_s > 0: +            cnt_s -= 1 +    else: +        cnt_s += 1