#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) templatebool chmax(T &x, T y){if(x>=y)return false;x=y;return true;} templatebool chmin(T &x, T y){if(x<=y)return false;x=y;return true;} const long long mod = 998244353; long long modpow(long long n, long long r){ long long ans = 1; while(r){ if(r%2)ans = ans * n % mod; n = n * n % mod; r /= 2; } return ans; } int main(){ long long ans = 0, c = 0; string S; cin >> S; for(auto x: S){ if(x=='M')c++; else ans = (ans+modpow(3, c))%mod; } cout << ans << endl; }