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