# coding: utf-8

X = eval(input())

tmp = " "

cnt = 0

for x in X:

    if x == "S":

        tmp += x

        cnt += 1

    elif x == "T" and tmp[-1]=="S":

            cnt -= 1

            tmp = tmp[0:len(tmp)-1]

    else:

        tmp += x

        cnt += 1

print(cnt)

# coding: utf-8

n_S, n_T = 0, 0



for c in eval(input()):

    if c == "S":

        n_S += 1

    else:

        if n_S:

            n_S -= 1

        else:

            n_T += 1

print((n_S + n_T))
# coding: utf-8
X = eval(input())
tmp = " "
cnt = 0
for x in X:
    if x == "S":
        tmp += x
        cnt += 1
    elif x == "T" and tmp[-1] == "S":
        cnt -= 1
        tmp = tmp[0 : len(tmp) - 1]
    else:
        tmp += x
        cnt += 1
print(cnt)

# coding: utf-8
n_S, n_T = 0, 0
for c in eval(input()):
    if c == "S":
        n_S += 1
    else:
        if n_S:
            n_S -= 1
        else:
            n_T += 1
print((n_S + n_T))

-X = eval(input()) -tmp = " " -cnt = 0 -for x in X: -    if x == "S": -        tmp += x -        cnt += 1 -    elif x == "T" and tmp[-1] == "S": -        cnt -= 1 -        tmp = tmp[0 : len(tmp) - 1] +n_S, n_T = 0, 0 +for c in eval(input()): +    if c == "S": +        n_S += 1 -        tmp += x -        cnt += 1 -print(cnt) +        if n_S: +            n_S -= 1 +        else: +            n_T += 1 +print((n_S + n_T))