N = int(eval(input()))

S1 = eval(input())

S2 = eval(input())



lis = []

i = 0

while i < N:

  if i == N-1:

    lis.append(1)

    i += 1

  elif S1[i] == S1[i+1]:

    lis.append(2)

    i += 2

  else:

    lis.append(1)

    i += 1

#print(lis)

ans = 3

if lis[0]==2:

  ans = 6

for i in range(len(lis)-1):

  if lis[i]==2:

    if lis[i+1]==2:

      ans *= 3

  else:

    ans *= 2

  ans %= 10**9+7

print(ans)



#print(*ans, sep='\n')

def solve():

    mod = 10**9+7

    N = int(eval(input()))

    s1 = eval(input())

    s2 = eval(input())

    lis = []

    i=0

    while i<N-1:

        if s1[i]==s1[i+1]:

            lis.append(2)

            i += 2

        else:

            lis.append(1)

            i += 1

    if i==N-1:

        lis.append(1)

    if N==1:

        lis = [1]

    if lis[0]==1:

        ans = 3

    else:

        ans = 6

    for i in range(len(lis)-1):

        if lis[i]==1:

            ans *= 2

            ans %= mod

        if lis[i]==2 and lis[i+1]==2:

            ans *=3

            ans %= mod

    return ans

print((solve()))
N = int(eval(input()))
S1 = eval(input())
S2 = eval(input())
lis = []
i = 0
while i < N:
    if i == N - 1:
        lis.append(1)
        i += 1
    elif S1[i] == S1[i + 1]:
        lis.append(2)
        i += 2
    else:
        lis.append(1)
        i += 1
# print(lis)
ans = 3
if lis[0] == 2:
    ans = 6
for i in range(len(lis) - 1):
    if lis[i] == 2:
        if lis[i + 1] == 2:
            ans *= 3
    else:
        ans *= 2
    ans %= 10**9 + 7
print(ans)
# print(*ans, sep='\n')

def solve():
    mod = 10**9 + 7
    N = int(eval(input()))
    s1 = eval(input())
    s2 = eval(input())
    lis = []
    i = 0
    while i < N - 1:
        if s1[i] == s1[i + 1]:
            lis.append(2)
            i += 2
        else:
            lis.append(1)
            i += 1
    if i == N - 1:
        lis.append(1)
    if N == 1:
        lis = [1]
    if lis[0] == 1:
        ans = 3
    else:
        ans = 6
    for i in range(len(lis) - 1):
        if lis[i] == 1:
            ans *= 2
            ans %= mod
        if lis[i] == 2 and lis[i + 1] == 2:
            ans *= 3
            ans %= mod
    return ans


print((solve()))

-N = int(eval(input())) -S1 = eval(input()) -S2 = eval(input()) -lis = [] -i = 0 -while i < N: +def solve(): +    mod = 10**9 + 7 +    N = int(eval(input())) +    s1 = eval(input()) +    s2 = eval(input()) +    lis = [] +    i = 0 +    while i < N - 1: +        if s1[i] == s1[i + 1]: +            lis.append(2) +            i += 2 +        else: +            lis.append(1) +            i += 1 -        i += 1 -    elif S1[i] == S1[i + 1]: -        lis.append(2) -        i += 2 +    if N == 1: +        lis = [1] +    if lis[0] == 1: +        ans = 3 -        lis.append(1) -        i += 1 -# print(lis) -ans = 3 -if lis[0] == 2: -    ans = 6 -for i in range(len(lis) - 1): -    if lis[i] == 2: -        if lis[i + 1] == 2: +        ans = 6 +    for i in range(len(lis) - 1): +        if lis[i] == 1: +            ans *= 2 +            ans %= mod +        if lis[i] == 2 and lis[i + 1] == 2: -    else: -        ans *= 2 -    ans %= 10**9 + 7 -print(ans) -# print(*ans, sep='\n') +            ans %= mod +    return ans + + +print((solve()))