X = eval(input())

s = ans = 0

for c in X:

    if c=='S':

        s += 1

    else:

        if s > 0:

            s -= 1

        else:

            ans += 1

print((ans+s))
S = eval(input())

s = ans = 0

for c in S:

    if c=='S':

        s += 1

    else:

        if s:

            s -= 1

        else:

            ans += 1

print((ans+s))
X = eval(input())
s = ans = 0
for c in X:
    if c == "S":
        s += 1
    else:
        if s > 0:
            s -= 1
        else:
            ans += 1
print((ans + s))

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

-X = eval(input()) +S = eval(input()) -for c in X: +for c in S: -        if s > 0: +        if s: