def main():

    N = int(eval(input()))

    S1 = eval(input())

    S2 = eval(input())

    cnt = 0

    MOD = 10 ** 9 + 7

    i = 0

    while i < N:

        if i == 0:

            if S1[i] == S2[i]:

                cnt += 3

                cnt %= MOD

                i += 1

            else:

                cnt += 6

                cnt %= MOD

                i += 2

        else:

            if S1[i] == S2[i]:

                if S1[i-1] == S2[i-1]:

                    cnt *= 2

                    cnt %= MOD

                    i += 1

                else:

                    cnt *= 1

                    cnt %= MOD

                    i += 1

            else:

                if S1[i-1] == S2[i-1]:

                    cnt *= 2

                    cnt %= MOD

                    i += 2

                else:

                    cnt *= 3

                    cnt %= MOD

                    i += 2



    print(cnt)









if __name__ == "__main__":

    main()
def main():

    N = int(eval(input()))

    S1 = eval(input())

    S2 = eval(input())

    MOD = 10 ** 9 + 7

    ans = 1

    cnt = 0

    while cnt < N:

        if cnt == 0:

            if S1[cnt] == S2[cnt]:

                ans *= 3

                cnt += 1

            else:

                ans *= 6

                cnt += 2

        else:

            if S1[cnt] == S2[cnt]:

                if S1[cnt-1] == S2[cnt-1]:

                    ans *= 2

                else:

                    ans *= 1

                cnt += 1

            else:

                if S1[cnt-1] == S2[cnt-1]:

                    ans *= 2

                else:

                    ans *= 3

                cnt += 2



        ans %= MOD



    print(ans)



if __name__ == "__main__":

    main()
def main():
    N = int(eval(input()))
    S1 = eval(input())
    S2 = eval(input())
    cnt = 0
    MOD = 10**9 + 7
    i = 0
    while i < N:
        if i == 0:
            if S1[i] == S2[i]:
                cnt += 3
                cnt %= MOD
                i += 1
            else:
                cnt += 6
                cnt %= MOD
                i += 2
        else:
            if S1[i] == S2[i]:
                if S1[i - 1] == S2[i - 1]:
                    cnt *= 2
                    cnt %= MOD
                    i += 1
                else:
                    cnt *= 1
                    cnt %= MOD
                    i += 1
            else:
                if S1[i - 1] == S2[i - 1]:
                    cnt *= 2
                    cnt %= MOD
                    i += 2
                else:
                    cnt *= 3
                    cnt %= MOD
                    i += 2
    print(cnt)


if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))
    S1 = eval(input())
    S2 = eval(input())
    MOD = 10**9 + 7
    ans = 1
    cnt = 0
    while cnt < N:
        if cnt == 0:
            if S1[cnt] == S2[cnt]:
                ans *= 3
                cnt += 1
            else:
                ans *= 6
                cnt += 2
        else:
            if S1[cnt] == S2[cnt]:
                if S1[cnt - 1] == S2[cnt - 1]:
                    ans *= 2
                else:
                    ans *= 1
                cnt += 1
            else:
                if S1[cnt - 1] == S2[cnt - 1]:
                    ans *= 2
                else:
                    ans *= 3
                cnt += 2
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

+    MOD = 10**9 + 7 +    ans = 1 -    MOD = 10**9 + 7 -    i = 0 -    while i < N: -        if i == 0: -            if S1[i] == S2[i]: -                cnt += 3 -                cnt %= MOD -                i += 1 +    while cnt < N: +        if cnt == 0: +            if S1[cnt] == S2[cnt]: +                ans *= 3 +                cnt += 1 -                cnt += 6 -                cnt %= MOD -                i += 2 +                ans *= 6 +                cnt += 2 -            if S1[i] == S2[i]: -                if S1[i - 1] == S2[i - 1]: -                    cnt *= 2 -                    cnt %= MOD -                    i += 1 +            if S1[cnt] == S2[cnt]: +                if S1[cnt - 1] == S2[cnt - 1]: +                    ans *= 2 -                    cnt *= 1 -                    cnt %= MOD -                    i += 1 +                    ans *= 1 +                cnt += 1 -                if S1[i - 1] == S2[i - 1]: -                    cnt *= 2 -                    cnt %= MOD -                    i += 2 +                if S1[cnt - 1] == S2[cnt - 1]: +                    ans *= 2 -                    cnt *= 3 -                    cnt %= MOD -                    i += 2 -    print(cnt) +                    ans *= 3 +                cnt += 2 +        ans %= MOD +    print(ans)