stack = []



for c in eval(input()):

    if c=='S' or len(stack)==0:

        stack.append(c)

    elif stack[-1]=='S':

        stack.pop()

    else:

        stack.append(c)

    #print(stack)



print((len(stack)))

s = eval(input())

SSS = 0

len = 0

for c in s:

    if c == 'S':

        SSS += 1

        len += 1

    elif SSS == 0:

        len += 1

    else:

        SSS -= 1

        len -= 1

    # print(len)

print(len)

stack = []
for c in eval(input()):
    if c == "S" or len(stack) == 0:
        stack.append(c)
    elif stack[-1] == "S":
        stack.pop()
    else:
        stack.append(c)
    # print(stack)
print((len(stack)))

s = eval(input())
SSS = 0
len = 0
for c in s:
    if c == "S":
        SSS += 1
        len += 1
    elif SSS == 0:
        len += 1
    else:
        SSS -= 1
        len -= 1
    # print(len)
print(len)

-stack = [] -for c in eval(input()): -    if c == "S" or len(stack) == 0: -        stack.append(c) -    elif stack[-1] == "S": -        stack.pop() +s = eval(input()) +SSS = 0 +len = 0 +for c in s: +    if c == "S": +        SSS += 1 +        len += 1 +    elif SSS == 0: +        len += 1 -        stack.append(c) -    # print(stack) -print((len(stack))) +        SSS -= 1 +        len -= 1 +    # print(len) +print(len)