s=input()

stack=[]

for i in range(len(s)):

    if len(stack)==0 or s[i]=="S":

        stack.append(s[i])

        continue

    if s[i]=="T":

        if stack[-1]=="S":

            stack.pop()

        else:

            stack.append(s[i])

print((len(stack)))
x = input()

stack = []

ans = 0

for i in range(len(x)):

    if x[i] == "S":

        stack.append("S")

    else:

        if len(stack) == 0:

            ans += 1

        else:

            stack.pop()

print(ans + len(stack))

s = input()
stack = []
for i in range(len(s)):
    if len(stack) == 0 or s[i] == "S":
        stack.append(s[i])
        continue
    if s[i] == "T":
        if stack[-1] == "S":
            stack.pop()
        else:
            stack.append(s[i])
print((len(stack)))

x = input()
stack = []
ans = 0
for i in range(len(x)):
    if x[i] == "S":
        stack.append("S")
    else:
        if len(stack) == 0:
            ans += 1
        else:
            stack.pop()
print(ans + len(stack))

-s = input() +x = input() -for i in range(len(s)): -    if len(stack) == 0 or s[i] == "S": -        stack.append(s[i]) -        continue -    if s[i] == "T": -        if stack[-1] == "S": +ans = 0 +for i in range(len(x)): +    if x[i] == "S": +        stack.append("S") +    else: +        if len(stack) == 0: +            ans += 1 +        else: -        else: -            stack.append(s[i]) -print((len(stack))) +print(ans + len(stack))