MOD = 998244353 S = input() N = len(S) ans = 0 M = 0 for i in range(N): if(S[i] == "M"): M += 1 else: ans += pow(3,M,MOD) ans %= MOD print(ans)