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