# 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())

cnt_S, cnt_T = 0, 0



for c in X:

    if c == "S":

        cnt_S += 1

    else:

        if cnt_S:

            cnt_S -= 1

        else:

            cnt_T += 1

print((cnt_S + cnt_T))
# 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())
cnt_S, cnt_T = 0, 0
for c in X:
    if c == "S":
        cnt_S += 1
    else:
        if cnt_S:
            cnt_S -= 1
        else:
            cnt_T += 1
print((cnt_S + cnt_T))

-# coding: utf-8 -n_S, n_T = 0, 0 -for c in eval(input()): +X = eval(input()) +cnt_S, cnt_T = 0, 0 +for c in X: -        n_S += 1 +        cnt_S += 1 -        if n_S: -            n_S -= 1 +        if cnt_S: +            cnt_S -= 1 -            n_T += 1 -print((n_S + n_T)) +            cnt_T += 1 +print((cnt_S + cnt_T))