s = input().rstrip()



removed = 0

cnt_s = cnt_t = 0



for c in s:

    if c == 'S':

        cnt_s += 1

    else:

        cnt_t += 1

    if cnt_t > cnt_s:

        removed += cnt_s

        cnt_s = cnt_t = 0

#     print(cnt_s,cnt_t)

removed += min(cnt_s,cnt_t)

print((len(s) - removed*2))
s = input().rstrip()

n = len(s)



removed = 0

cnt_s = cnt_t = 0



for i in range(n):

    if s[i] == 'S':

        cnt_s += 1

    else:

        cnt_t += 1

    if i == n-1:

        removed += min(cnt_s,cnt_t)

    elif cnt_t > cnt_s:

        removed += cnt_s

        cnt_s = cnt_t = 0

#     print(cnt_s,cnt_t)

print((len(s) - removed*2))
s = input().rstrip()
removed = 0
cnt_s = cnt_t = 0
for c in s:
    if c == "S":
        cnt_s += 1
    else:
        cnt_t += 1
    if cnt_t > cnt_s:
        removed += cnt_s
        cnt_s = cnt_t = 0
#     print(cnt_s,cnt_t)
removed += min(cnt_s, cnt_t)
print((len(s) - removed * 2))

s = input().rstrip()
n = len(s)
removed = 0
cnt_s = cnt_t = 0
for i in range(n):
    if s[i] == "S":
        cnt_s += 1
    else:
        cnt_t += 1
    if i == n - 1:
        removed += min(cnt_s, cnt_t)
    elif cnt_t > cnt_s:
        removed += cnt_s
        cnt_s = cnt_t = 0
#     print(cnt_s,cnt_t)
print((len(s) - removed * 2))

+n = len(s) -for c in s: -    if c == "S": +for i in range(n): +    if s[i] == "S": -    if cnt_t > cnt_s: +    if i == n - 1: +        removed += min(cnt_s, cnt_t) +    elif cnt_t > cnt_s: -removed += min(cnt_s, cnt_t)