def main():

    md = 998244353

    s = eval(input())

    n = len(s)

    if s.count(s[0]) == n:

        print((1))

        exit()

    if n == 2:

        print((2))

        exit()

    if n == 3:

        if s[0] == s[-1]:

            print((7))

        elif s[0] == s[1] or s[1] == s[2]:

            print((6))

        else:

            print((3))

        exit()

    ord0 = ord("a")

    a = [ord(c) - ord0 for c in s]

    r = sum(a) % 3

    dp = [[[[0] * 3 for _ in range(2)] for _ in range(3)] for _ in range(n)]

    for m in range(3):

        dp[0][m][0][m] = 1

    # print(a)

    # print(dp)

    for i in range(n - 1):

        for j in range(3):

            for k in range(2):

                for m in range(3):

                    pre = dp[i][j][k][m]  # iけた j余り k連続有無 m前の位

                    for nm in range(3):

                        nj = (j + nm) % 3

                        if nm == m:

                            dp[i + 1][nj][1][nm] = (dp[i + 1][nj][1][nm] + pre) % md

                        else:

                            dp[i + 1][nj][k][nm] = (dp[i + 1][nj][k][nm] + pre) % md

    d = 1

    for c0, c1 in zip(s, s[1:]):

        if c0 == c1:

            d = 0

            break

    print(((sum(dp[n - 1][r][1]) + d) % md))



main()

def main():

    md = 998244353

    s = eval(input())

    n = len(s)

    al = True  # allすべて同じ文字

    an = 1  # any連続が存在すると0

    for c0, c1 in zip(s, s[1:]):

        if c0 == c1:

            an = 0

        else:

            al = False

        if an == 0 and not al: break

    if al:

        print((1))

        exit()

    if n == 2:

        print((2))

        exit()

    if n == 3:

        if s[0] == s[-1]:

            print((7))

        elif s[0] == s[1] or s[1] == s[2]:

            print((6))

        else:

            print((3))

        exit()

    #print(n)

    #print(an)

    ord0=ord("a")

    r = sum(ord(c) - ord0 for c in s) % 3

    if n%3==0:

        d=pow(2,n//3-1,md)

        if r==0:

            an-=d*2

        else:

            an+=d

    print(((pow(3, n - 1, md) - pow(2, n - 1, md) + an) % md))



main()

def main():
    md = 998244353
    s = eval(input())
    n = len(s)
    if s.count(s[0]) == n:
        print((1))
        exit()
    if n == 2:
        print((2))
        exit()
    if n == 3:
        if s[0] == s[-1]:
            print((7))
        elif s[0] == s[1] or s[1] == s[2]:
            print((6))
        else:
            print((3))
        exit()
    ord0 = ord("a")
    a = [ord(c) - ord0 for c in s]
    r = sum(a) % 3
    dp = [[[[0] * 3 for _ in range(2)] for _ in range(3)] for _ in range(n)]
    for m in range(3):
        dp[0][m][0][m] = 1
    # print(a)
    # print(dp)
    for i in range(n - 1):
        for j in range(3):
            for k in range(2):
                for m in range(3):
                    pre = dp[i][j][k][m]  # iけた j余り k連続有無 m前の位
                    for nm in range(3):
                        nj = (j + nm) % 3
                        if nm == m:
                            dp[i + 1][nj][1][nm] = (dp[i + 1][nj][1][nm] + pre) % md
                        else:
                            dp[i + 1][nj][k][nm] = (dp[i + 1][nj][k][nm] + pre) % md
    d = 1
    for c0, c1 in zip(s, s[1:]):
        if c0 == c1:
            d = 0
            break
    print(((sum(dp[n - 1][r][1]) + d) % md))


main()

def main():
    md = 998244353
    s = eval(input())
    n = len(s)
    al = True  # allすべて同じ文字
    an = 1  # any連続が存在すると0
    for c0, c1 in zip(s, s[1:]):
        if c0 == c1:
            an = 0
        else:
            al = False
        if an == 0 and not al:
            break
    if al:
        print((1))
        exit()
    if n == 2:
        print((2))
        exit()
    if n == 3:
        if s[0] == s[-1]:
            print((7))
        elif s[0] == s[1] or s[1] == s[2]:
            print((6))
        else:
            print((3))
        exit()
    # print(n)
    # print(an)
    ord0 = ord("a")
    r = sum(ord(c) - ord0 for c in s) % 3
    if n % 3 == 0:
        d = pow(2, n // 3 - 1, md)
        if r == 0:
            an -= d * 2
        else:
            an += d
    print(((pow(3, n - 1, md) - pow(2, n - 1, md) + an) % md))


main()

-    if s.count(s[0]) == n: +    al = True  # allすべて同じ文字 +    an = 1  # any連続が存在すると0 +    for c0, c1 in zip(s, s[1:]): +        if c0 == c1: +            an = 0 +        else: +            al = False +        if an == 0 and not al: +            break +    if al: +    # print(n) +    # print(an) -    a = [ord(c) - ord0 for c in s] -    r = sum(a) % 3 -    dp = [[[[0] * 3 for _ in range(2)] for _ in range(3)] for _ in range(n)] -    for m in range(3): -        dp[0][m][0][m] = 1 -    # print(a) -    # print(dp) -    for i in range(n - 1): -        for j in range(3): -            for k in range(2): -                for m in range(3): -                    pre = dp[i][j][k][m]  # iけた j余り k連続有無 m前の位 -                    for nm in range(3): -                        nj = (j + nm) % 3 -                        if nm == m: -                            dp[i + 1][nj][1][nm] = (dp[i + 1][nj][1][nm] + pre) % md -                        else: -                            dp[i + 1][nj][k][nm] = (dp[i + 1][nj][k][nm] + pre) % md -    d = 1 -    for c0, c1 in zip(s, s[1:]): -        if c0 == c1: -            d = 0 -            break -    print(((sum(dp[n - 1][r][1]) + d) % md)) +    r = sum(ord(c) - ord0 for c in s) % 3 +    if n % 3 == 0: +        d = pow(2, n // 3 - 1, md) +        if r == 0: +            an -= d * 2 +        else: +            an += d +    print(((pow(3, n - 1, md) - pow(2, n - 1, md) + an) % md))