now = 1 mod = 998244353 ans = 0 for s in input(): if s == "M": now = now * 3 % mod else: ans = (ans + now) % mod print(ans)