x = eval(input())

stack = []

ans = 0

for i in range(len(x)):

    if x[i] == "S":

        stack.append(x[i])

    elif len(stack) > 0:

        stack.pop()

        ans += 1

print((len(x) - ans * 2))
x = eval(input())

count = 0

st = 0

for i in range(len(x)):

    if x[i] == "S":

        count += 1

    elif count > 0:

        count -= 1

        st += 1

print((len(x) - st * 2))
x = eval(input())
stack = []
ans = 0
for i in range(len(x)):
    if x[i] == "S":
        stack.append(x[i])
    elif len(stack) > 0:
        stack.pop()
        ans += 1
print((len(x) - ans * 2))

x = eval(input())
count = 0
st = 0
for i in range(len(x)):
    if x[i] == "S":
        count += 1
    elif count > 0:
        count -= 1
        st += 1
print((len(x) - st * 2))

-stack = [] -ans = 0 +count = 0 +st = 0 -        stack.append(x[i]) -    elif len(stack) > 0: -        stack.pop() -        ans += 1 -print((len(x) - ans * 2)) +        count += 1 +    elif count > 0: +        count -= 1 +        st += 1 +print((len(x) - st * 2))