from collections import deque

d = deque()

X = eval(input())

for c in X:

    d.append(c)

    while len(d) >= 2:

        new = d.pop()

        last = d.pop()

        if last == "S" and new == "T":

            continue

        else:

            d.append(last)

            d.append(new)

            break

print((len(d)))
from collections import deque

d = deque()

X = eval(input())

for c in X:

    if d:

        last = d.pop()

        if last == "S" and c == "T":

            pass

        else:

            d.append(last)

            d.append(c)

    else:

        d.append(c)

print((len(d)))

from collections import deque

d = deque()
X = eval(input())
for c in X:
    d.append(c)
    while len(d) >= 2:
        new = d.pop()
        last = d.pop()
        if last == "S" and new == "T":
            continue
        else:
            d.append(last)
            d.append(new)
            break
print((len(d)))

from collections import deque

d = deque()
X = eval(input())
for c in X:
    if d:
        last = d.pop()
        if last == "S" and c == "T":
            pass
        else:
            d.append(last)
            d.append(c)
    else:
        d.append(c)
print((len(d)))

-    d.append(c) -    while len(d) >= 2: -        new = d.pop() +    if d: -        if last == "S" and new == "T": -            continue +        if last == "S" and c == "T": +            pass -            d.append(new) -            break +            d.append(c) +    else: +        d.append(c)