#include #include using namespace std; using mint = atcoder::modint998244353; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string S; cin >> S; mint p = 1; mint ans = 0; for (char c : S) { if (c == 'M') p *= 3; else ans += p; } cout << ans.val() << "\n"; }