import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln

void main() {
	const int MOD = 998244353;
	string s = chomp(readln());
	int n = to!int(s.length);
	int[] a = new int[n];
	foreach (i; 0..n) {
		a[i] = s[i]-'a';
	}

	if (n == 2) {
		writeln((a[0]==a[1]) ? 1 : 2);
		return;
	}
	if (n == 3) {
		a.sort;
		int ans = 6;
		if (a[0] == a[2]) ans = 1;
		if (a[2]-a[0] == 2) ans = 3;
		writeln(ans);
		return;
	}

	long ans = 1;
	foreach (i; 0..n-1) ans = (ans*3)%MOD;
	bool unstable() {
		foreach (i; 1..n) {
			if (a[i-1] == a[i]) return false;
		}
		return true;
	}
	if (unstable()) ans++;

	long[][][] dp = new long[][][](n,3,3);
	foreach (i; 0..3) dp[0][i][i] = 1;
	foreach (i; 1..n) {
		foreach (j; 0..3) foreach (k; 0..3) {
			foreach (x; 0..3) {
				if (k == x) continue;
				(dp[i][(j+x)%3][x] += dp[i-1][j][k]) %= MOD;
			}
		}
	}
	ans -= dp[n-1][a.sum%3].sum;
	ans = (ans%MOD+MOD)%MOD;
	writeln(ans);
}