#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}



ll nextLong() { ll x; scanf("%lld", &x); return x;}

const ll MOD = 998244353;

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint& operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}
  mint& operator-=(const mint a) {if ((x += MOD-a.x) >= MOD) x -= MOD;return *this;}
  mint& operator*=(const mint a) {(x *= a.x) %= MOD;return *this;}
  mint operator+(const mint a) const {mint res(*this);return res+=a;}
  mint operator-(const mint a) const {mint res(*this);return res-=a;}
  mint operator*(const mint a) const {mint res(*this);return res*=a;}
  mint pow(ll b) const {
    mint res(1), a(*this);
    while (b) {
      if (b & 1) res *= a;
      a *= a;
      b >>= 1;
    }
    return res;
  }
  // for prime MOD
  mint inv() const {return pow(MOD-2);}
  mint& operator/=(const mint a) {return (*this) *= a.inv();}
  mint operator/(const mint a) const {mint res(*this);return res/=a;}
};
ostream& operator<<(ostream& os, const mint& a) {os << a.x; return os;}


const int MAX_N = 212345;
mint dp[MAX_N][3][3];

int parity(string s) {
  int res = 0;
  REP(i, s.size()) {
    res += (s[i] - 'a');
  }
  return res % 3;
}

int type(string s) {

  int t = 0;
  bool all_eq = true;

  REP(i, (int)s.size() - 1) {
    if (s[i] == s[i+1]) t = 1;
    if (s[i] != s[i+1]) all_eq = false;
  }
  if (all_eq) t = 2;

  return t;
}


char other(char c1, char c2) {
  if (c1 > c2) swap(c1, c2);
  if (c1 == 'a' && c2 == 'b') return 'c';
  if (c1 == 'b' && c2 == 'c') return 'a';
  if (c1 == 'a' && c2 == 'c') return 'b';
  return '?';
}

ll naive(string s) {

  queue<string> q;
  set<string> vis;

  q.push(s);
  vis.insert(s);
  while (!q.empty()) {
    s = q.front(); q.pop();

    for (int i = 0; i + 1 < (int)s.size(); i++) {
      if (s[i] != s[i+1]) {
        string t = s;
        t[i] = t[i+1] = other(s[i], s[i+1]);
        if (vis.count(t) == 0) {
          vis.insert(t);
          q.push(t);
        }
      }
    }
  }
  // for (auto x : vis) cout << x << endl;
  return vis.size();
}



int main2() {
  REP(i, MAX_N) REP(j, 3) REP(k, 3) dp[i][j][k] = 0;

  string s; cin >> s;
  int N = s.size();


  if (N <= 6) {
    cout << naive(s) << endl;
    return 0;
  }

  int p = parity(s);
  int t = type(s);

  if (t == 2) {
    cout << 1 << endl;
    return 0;
  }

  dp[1][0][0] = 1;
  dp[1][1][1] = 1;
  dp[1][2][2] = 1;
  for (int i = 1; i < N; i++) {
    for (int r = 0; r < 3; r++) {
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++) {
          if (j == k) continue;
          dp[i+1][(r+k)%3][k] += dp[i][r][j];
        }
      }
    }
  }

  // cout << "N=" << N << endl;

  mint x = dp[N][p][0] + dp[N][p][1] + dp[N][p][2];
  mint z = (N % 3 == 0) ? 3 : 0;
  mint y = mint(3).pow(N-1) - x - z;
  // cout << "N=" << N << ", y=" << y << endl;
  mint ans = y;
  if (t == 0) ans += 1;
  ans += z;
  cout << ans << endl;
  return 0;
}


int main() {

  if (0) {

    map<int, int> counter;

    int N = 3;
    for (int i = 0; i < pow(3, N); i++) {
      string s = "";
      int ii = i;
      REP(_, N) { s += (char)('a' + ii % 3); ii /= 3; }

      // if (parity(s) == 1) {
      //   ll num = naive(s);
      //   cout << s << " p=" << parity(s) << " " << num << endl;
      // }

      int type = 0;
      bool all_eq = true;
      for (int j = 0; j + 1 < N; j++) {
        if (s[j] == s[j+1]) type = 1;
        if (s[j] != s[j+1]) all_eq = false;
      }
      if (all_eq) type = 2;
      int key = 10000 + parity(s) * 100 + type;
      counter[key]++;

    }

      for (int p = 0; p < 3; p++) {
        for (int t = 0; t < 3; t++) {
          cout << counter[10000 + p * 100 + t] << " ";
        }
        cout << endl;
      }
    // pv(ALL(counter));
  }
  // cout << naive("abcabc") << endl;
  // return 0;

// #ifdef LOCAL
  // for (;!cin.eof();cin>>ws)
// #endif
    main2();
  return 0;
}

Measured memory_bytes: 18840