#include using namespace std; using ll = long long; bool chmax(auto &a, auto b) { return a < b ? a = b, 1 : 0; } bool chmin(auto &a, auto b) { return a > b ? a = b, 1 : 0; } template struct modint { using M = modint; ll x; modint() : x(0) {} constexpr modint(ll v) : x(v % MOD) { if (x < 0) x += MOD; } ll val() { return x; } friend M operator+(M a, M b) { return a.x + b.x; } friend M operator-(M a, M b) { return a.x - b.x; } friend M operator*(M a, M b) { return a.x * b.x; } friend M operator+=(M& a, M b) { return a = a + b; } friend M operator*=(M& a, M b) { return a = a * b; } M pow(ll k) const { M a = x, res = 1; while (k > 0) { if (k & 1) res *= a; a *= a; k >>= 1; } return res; } }; using mint = modint<998244353>; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string S; cin >> S; int N = S.size(); mint ans = 0; vector dp(N + 1); dp[0] = 1; for (int i = 0; i < N; ++i) { if (S[i] == 'A') { ans += dp[i]; dp[i + 1] = dp[i]; } else { dp[i + 1] = 3 * dp[i]; } } cout << ans.val() << '\n'; }