#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template <typename T>
T inverse(T a, T m) {
  T u = 0, v = 1;
  while (a != 0) {
    T t = m / a;
    m -= t * a; std::swap(a, m);
    u -= t * v; std::swap(u, v);
  }
  assert(m == 1);
  return u;
}
template <typename T>
class modular {
  private:
    int value;
  public:
    constexpr modular() = default;
    constexpr modular(const modular&) = default;
    constexpr modular(modular&&) = default;
    modular& operator=(const modular&) = default;
    modular& operator=(modular&&) = default;

    template <typename U>
    modular (const U& x) {value = normalize(x);}

    template <typename U>
    static auto normalize(const U& x) {
      int v = static_cast<int>(-mod() <= x && x < mod() ? x : x % mod());
      if (v < 0) v += mod();
      return v;
    }

    auto const& operator()() const { return value; }
    template <typename U>
    explicit operator U() const { return static_cast<U>(value); }
    constexpr static auto mod() { return T::value; }

    auto& operator+=(const modular& other) {
      if ((value += other.value) >= mod()) value -= mod();
      return *this;
    }
    auto& operator-=(const modular& other) {
      if ((value -= other.value) < 0) value += mod();
      return *this;
    }
    template <typename U>
    auto& operator+=(const U& other) {return *this += modular(other); }
    template <typename U>
    auto& operator-=(const U& other) {return *this -= modular(other); }
    auto operator-() const { return modular(-value); }
    auto& operator++() {return *this += 1;}
    auto& operator--() {return *this -= 1;}
    auto  operator++(int) {modular result(*this); operator++(); return result;}
    auto  operator--(int) {modular result(*this); operator--(); return result;}

    template <typename U = T>
    auto& operator*=(const modular& rhs) {
      value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value));
      return *this;
    }
    auto& operator/=(const modular& other) {
      return *this *= modular(inverse(other.value, mod()));
    }
};
template <typename T> struct is_modular : std::false_type {};
template <typename T> struct is_modular <modular<T>> : std::true_type{};
template <typename T> constexpr bool is_modular_v = is_modular<T>::value;

template <typename T> bool operator==(const modular<T>& lhs, const modular<T>& rhs) { return lhs() == rhs(); }
template <typename T, typename U> bool operator==(const modular<T>& lhs, U rhs) { return lhs == modular<T>(rhs); }
template <typename T, typename U> bool operator==(U lhs, const modular<T>& rhs) { return modular<T>(lhs) == rhs; }

template <typename T> bool operator!=(const modular<T>& lhs, const modular<T>& rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(const modular<T>& lhs, U rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(U lhs, const modular<T>& rhs) { return !(lhs == rhs); }

template <typename T> modular<T> operator+(const modular<T>& lhs, const modular<T>& rhs) { return modular<T>(lhs) += rhs; }
template <typename T, typename U> modular<T> operator+(const modular<T>& lhs, U rhs) { return modular<T>(lhs) += rhs; }
template <typename T, typename U> modular<T> operator+(U lhs, const modular<T>& rhs) { return modular<T>(lhs) += rhs; }

template <typename T> modular<T> operator-(const modular<T>& lhs, const modular<T>& rhs) { return modular<T>(lhs) -= rhs; }
template <typename T, typename U> modular<T> operator-(const modular<T>& lhs, U rhs) { return modular<T>(lhs) -= rhs; }
template <typename T, typename U> modular<T> operator-(U lhs, const modular<T>& rhs) { return modular<T>(lhs) -= rhs; }

template <typename T> modular<T> operator*(const modular<T>& lhs, const modular<T>& rhs) { return modular<T>(lhs) *= rhs; }
template <typename T, typename U> modular<T> operator*(const modular<T>& lhs, U rhs) { return modular<T>(lhs) *= rhs; }
template <typename T, typename U> modular<T> operator*(U lhs, const modular<T>& rhs) { return modular<T>(lhs) *= rhs; }

template <typename T> modular<T> operator/(const modular<T>& lhs, const modular<T>& rhs) { return modular<T>(lhs) /= rhs; }
template <typename T, typename U> modular<T> operator/(const modular<T>& lhs, U rhs) { return modular<T>(lhs) /= rhs; }
template <typename T, typename U> modular<T> operator/(U lhs, const modular<T>& rhs) { return modular<T>(lhs) /= rhs; }

template<typename T, typename U>
modular<T> power (const modular<T>& a, U b) {
  assert(b >= 0);
  modular<T> x = a, ret = 1;
  for (; b > 0; b /= 2) {
    if (b % 2 == 1) ret *= x;
    x *= x;
  }
  return ret;
}

template <typename T>
std::string to_string(const modular<T>& a) {
  return std::to_string(a());
}
template <typename T>
auto operator<<(std::ostream& os, const T& a)
  -> std::enable_if_t<is_modular_v<T>, std::ostream&>{
    return os << a();
  }
template <typename T>
auto operator>>(std::istream& is, T& a)
  -> std::enable_if_t<is_modular_v<T>, std::istream&> {
  long long x; is >> x;
  a = T(x);
  return is;
}

// using mod_type = int;

// struct variable_mod { static mod_type value; };
// mod_type variable_mod::value;
// mod_type& mod = variable_mod::value;
// using mint = modular< variable_mod >;

constexpr int mod = 998244353;
using mint = modular<std::integral_constant<std::decay_t<decltype(mod)>, mod>>;

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

template <typename T>
auto make_vector_impl(size_t sz, T t) {return std::vector<T>(sz, t);}

template <size_t N, typename T, typename U, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz, U u) {return make_vector_impl(sz, T(u));}

template <size_t N, typename T, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz) {return std::vector<T>(sz);}

template <size_t N, typename T, typename... Args, std::enable_if_t<N != 1, std::nullptr_t> = nullptr>
auto make_vector(size_t a, Args... args) {return make_vector_impl(a, make_vector<N - 1, T>(args...));}

template <typename T, typename Size_t>
auto& at(T& t, Size_t i) {return t.at(i);}

template <typename T, typename Size_t, typename... Args>
auto& at(T& t, Size_t i, Args... args) {return at(t.at(i), args...);}

auto strongly_connected_component_decomposition(
  std::vector< std::vector< int > > const & graph )
{
  int const n = graph.size();
  std::vector< int > ckd(n, false);
  std::vector< int > ord;

  auto const dfs = [&graph, &ckd, &ord](auto&& f, auto crr) -> void {
    ckd.at(crr) = true;
    for (auto const nxt : graph.at(crr)) {
      if (ckd.at(nxt)) continue;
      f(f, nxt);
    }
    ord.emplace_back(crr);
  };
  for (auto i = 0; i < n; i++) {
    if (ckd.at(i)) continue;
    dfs(dfs, i);
  }
  std::reverse(ord.begin(), ord.end());

  std::vector< std::vector< int > > rgraph(n);
  for (auto i = 0; i < n; i++) {
    for (auto j : graph.at(i)) {
      rgraph.at(j).emplace_back(i);
    }
  }

  auto now = 0;
  std::vector< int > cmp(n, -1);
  auto const rdfs = [&rgraph, &cmp, &now](auto&& f, auto crr) -> void {
    cmp.at(crr) = now;
    for (auto const nxt : rgraph.at(crr)) {
      if (cmp.at(nxt) != -1) continue;
      f(f, nxt);
    }
  };
  for (auto i : ord) {
    if (cmp.at(i) != -1) continue;
    rdfs(rdfs, i);
    now++;
  }
  return cmp;
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  // auto draw = [&] (int n) {
  //   int N = 1;
  //   loop(n) N *= 3;

  //   auto encode = [&] (std::vector<int> a) {
  //     int ans = 0;
  //     while (!a.empty()) {
  //       ans *= 3;
  //       int x = a.back();
  //       a.pop_back();
  //       ans += x;
  //     }
  //     return ans;
  //   };

  //   auto decode = [&] (int x) {
  //     std::vector<int> ans;
  //     loop(n) {
  //       ans.emplace_back(x%3);
  //       x /= 3;
  //     }
  //     return ans;
  //   };

  //   std::vector<std::vector<int>> graph(N);

  //   rep(s,0,N) {
  //     auto from = decode(s);
  //     rep(i,0,n-1) {
  //       int x = from.at(i);
  //       int y = from.at(i+1);
  //       if (x==y) continue;
  //       int z = 3^x^y;
  //       auto target = from;
  //       target.at(i) = z;
  //       target.at(i+1) = z;
  //       int t = encode(target);
  //       graph.at(s).emplace_back(t);
  //     }
  //   }
  //   // debug(graph);

  //   rep(s,0,N) {
  //     for (int t : graph.at(s)) {
  //       // printf("\"%lld\" -> \"%d\"\n", s, t);
  //     }
  //   }

  //   auto cmp = strongly_connected_component_decomposition(graph);
  //   // debug(cmp);
  //   std::vector<std::vector<int>> members(N);
  //   rep(i,0,N) {
  //     members.at(cmp.at(i)).emplace_back(i);
  //   }
  //   int iso = 0;
  //   for (auto&& v : members) {
  //     if (v.empty()) continue;
  //     if (v.size() == 1u) {
  //       iso++;
  //       int x = v.front();
  //       debug(decode(x));
  //     } else {
  //       debug(v.size());
  //     }
  //   }
  //   debug(iso);
  // };
  // draw(9);

  auto calc = [&] (std::vector<int> const& a) {
    int n = a.size();
    int N = 1;
    loop(n) N *= 3;

    auto encode = [&] (std::vector<int> a) {
      int ans = 0;
      while (!a.empty()) {
        ans *= 3;
        int x = a.back();
        a.pop_back();
        ans += x;
      }
      return ans;
    };

    auto decode = [&] (int x) {
      std::vector<int> ans;
      loop(n) {
        ans.emplace_back(x%3);
        x /= 3;
      }
      return ans;
    };

    std::vector<std::vector<int>> graph(N);

    rep(s,0,N) {
      auto from = decode(s);
      rep(i,0,n-1) {
        int x = from.at(i);
        int y = from.at(i+1);
        if (x==y) continue;
        int z = 3^x^y;
        auto target = from;
        target.at(i) = z;
        target.at(i+1) = z;
        int t = encode(target);
        graph.at(s).emplace_back(t);
      }
    }
    // debug(graph);

    int me = encode(a);
    std::vector<int> ckd(N,false);
    std::queue<int> que;
    que.push(me);
    while (!que.empty()) {
      int x = que.front(); que.pop();
      ckd.at(x) = true;
      for (int y : graph.at(x)) {
        if (ckd.at(y)) continue;
        que.push(y);
      }
    }
    int ans = std::accumulate(all(ckd),0);
    return ans;
  };

  std::string s; std::cin >> s;
  int n = s.length();
  std::vector<int> a(n);
  std::transform(all(s),a.begin(),[](char c){ return c - 'a'; });
  if (n==3) {
    int ans = calc(a);
    std::cout << ans << std::endl;
    return 0;
  }
  if (a == std::vector<int>(n,a.front())) {
    std::cout << 1 << std::endl;
    return 0;
  }

  auto dp = make_vector<2,mint>(3,3);
  rep(i,0,3) {
    at(dp,i,i) = 1;
  }
  loop(n-1) {
    auto new_dp = make_vector<2,mint>(3,3);
    rep(i,0,3) rep(j,0,3) rep(k,0,3) {
      if (j==k) continue;
      mint crr = at(dp,i,j);
      at(new_dp,(i+k)%3,k) += crr;
    }
    new_dp.swap(dp);
    debug(dp);
  }

  int p = std::accumulate(all(a),0) % 3;

  mint sum = power(mint{3}, n - 1);
  mint different = 0;
  rep(i,0,3) {
    different += at(dp,p,i);
  }

  bool found = false;
  rep(i,0,n-1) {
    found |= a.at(i) == a.at(i+1);
  }

  debug(sum,different,found);
  mint ans = sum - different + !found;
  std::cout << ans << std::endl;
  return 0;
}

/*
余りが同じものにしか移れません。
長さが 4 以上のとき、強連結成分分解は、
同じもの連打が行き止まりで隣同士違うものが始まりな以外はひとつです。
長さ 3 のときには全探索です。

隣同士違うものの数は、DP で求めます。
今の余りの数と、前回の数字が状態です。　
*/

Measured memory_bytes: 2196