mod = 998244353 S = input() ans = 0 k = 0 for s in S: if s == "M": k += 1 else: ans += pow(3, k, mod) ans %= mod print(ans)