MOD = 998244353 S = input().strip() cnt = 0 ans = 0 for c in S: if c=="M": cnt += 1 else: ans = (ans+pow(3,cnt,MOD))%MOD print(ans)