md = 998244353 s = input() m = 0 ans = 0 for c in s: if c == "M": m += 1 else: ans += pow(3, m, md) ans %= md print(ans % md)