#include using namespace std; using ll=long long; #include using namespace atcoder; using mint=modint998244353; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); string S; cin>>S; int N=S.size(); mint an=0; for(int i=N-1;i>=0;i--){ if(S[i]=='A')an++; else an*=3; } cout<