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