S = input() mod = 998244353 sumM = 0 ans = 0 for c in S: if c == "M": sumM += 1 elif c == "A": ans = (ans + pow(3, sumM, mod)) % mod print(ans)