X = eval(input())

st = 0

s = 0

t = 0

for x in X:

    if x == "S":

        st += min(s, t)

        if t > 0:

            s -= min(s, t)

            t = 0

        s += 1

    elif x == "T" and s > 0:

        t += 1

st += min(s, t)

print((len(X) - 2 * st))
X = eval(input())

s = 0

t = 0

stack = []

for x in X:

    if x == "S":

        stack.append(x)

    elif x == "T" and (len(stack)==0 or stack[-1] == "T"):

        stack.append(x)

    else:

        stack.pop()

print((len(stack)))
X = eval(input())
st = 0
s = 0
t = 0
for x in X:
    if x == "S":
        st += min(s, t)
        if t > 0:
            s -= min(s, t)
            t = 0
        s += 1
    elif x == "T" and s > 0:
        t += 1
st += min(s, t)
print((len(X) - 2 * st))

X = eval(input())
s = 0
t = 0
stack = []
for x in X:
    if x == "S":
        stack.append(x)
    elif x == "T" and (len(stack) == 0 or stack[-1] == "T"):
        stack.append(x)
    else:
        stack.pop()
print((len(stack)))

-st = 0 +stack = [] -        st += min(s, t) -        if t > 0: -            s -= min(s, t) -            t = 0 -        s += 1 -    elif x == "T" and s > 0: -        t += 1 -st += min(s, t) -print((len(X) - 2 * st)) +        stack.append(x) +    elif x == "T" and (len(stack) == 0 or stack[-1] == "T"): +        stack.append(x) +    else: +        stack.pop() +print((len(stack)))