We have a board with a 2 \times N grid.
Snuke covered the board with N dominoes without overlaps.
Here, a domino can cover a 1 \times 2 or 2 \times 1 square.
Then, Snuke decided to paint these dominoes using three colors: red, cyan and green.
Two dominoes that are adjacent by side should be painted by different colors.
Here, it is not always necessary to use all three colors.
Find the number of such ways to paint the dominoes, modulo 1000000007.
The arrangement of the dominoes is given to you as two strings S_1 and S_2 in the following manner:
 - Each domino is represented by a different English letter (lowercase or uppercase).
 - The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left.

-----Constraints-----
 - 1 \leq N \leq 52
 - |S_1| = |S_2| = N
 - S_1 and S_2 consist of lowercase and uppercase English letters.
 - S_1 and S_2 represent a valid arrangement of dominoes.

-----Input-----
Input is given from Standard Input in the following format:
N
S_1
S_2

-----Output-----
Print the number of such ways to paint the dominoes, modulo 1000000007.

-----Sample Input-----
3
aab
ccb

-----Sample Output-----
6

There are six ways as shown below:

Difficulty: HARD

Starter code:

Solutions:
N = int(input())
l = ''
mod = 10 ** 9 + 7
Sa = list(input())
Sb = list(input())
for i in range(N):
	if Sa[i] == Sb[i]:
		l += 'X'
	else:
		l += 'Y'
l = l.replace('YY', 'Y')
ans = 6 if l[0] == 'Y' else 3
for i in range(1, len(l)):
	if l[i] == 'Y' and l[i - 1] == 'Y':
		ans *= 3
	if l[i] == 'X' and l[i - 1] == 'X':
		ans *= 2
	if l[i] == 'Y' and l[i - 1] == 'X':
		ans *= 2
	ans = ans % mod
print(ans)


n = int(input())
mod = 10 ** 9 + 7
s1 = input()
s2 = input()
if s1[0] == s2[0]:
	i = 1
	ans = 3
	bef = 'x'
else:
	i = 2
	ans = 6
	bef = 'y'
while True:
	if i == n:
		break
	if s1[i] == s2[i]:
		if bef == 'x':
			ans *= 2
		if bef == 'y':
			ans *= 1
		i += 1
		bef = 'x'
	else:
		if bef == 'x':
			ans *= 2
		if bef == 'y':
			ans *= 3
		i += 2
		bef = 'y'
	ans %= mod
print(ans % mod)


N = int(input())
S1 = list(input())
S2 = list(input())
p = 10 ** 9 + 7
out = 1
if S1[0] == S2[0]:
	out *= 3
	s = 1
	left = 'V'
else:
	out *= 3 * 2
	s = 2
	left = 'H'
while s < N:
	if S1[s] == S2[s]:
		now = 'V'
	else:
		now = 'H'
	if left == 'V' and now == 'V':
		out *= 2
		s += 1
	elif left == 'V' and now == 'H':
		out *= 2 * 1
		s += 2
	elif left == 'H' and now == 'V':
		out *= 1
		s += 1
	elif left == 'H' and now == 'H':
		out *= 3
		s += 2
	out = out % p
	left = now
print(out)


n = int(input())
s = [input() for _ in range(2)]
mod = 1000000007
cnt = [[0, 0, 0], [0, 2, 2], [0, 1, 3]]
if n == 1:
	print(3)
elif n == 2:
	print(6)
else:
	c = []
	i = 0
	while i < n:
		if s[0][i] == s[1][i]:
			c.append(1)
			i += 1
		elif i + 1 < n and s[0][i] == s[0][i + 1]:
			c.append(2)
			i += 2
	if c[0] == 1:
		ans = 3
	elif c[0] == 2:
		ans = 6
	for i in range(1, len(c)):
		ans *= cnt[c[i - 1]][c[i]]
		ans %= mod
	print(ans % mod)


class modint:
	mod = 0
	has_been_set = False

	def __init__(self, v=0, m=None):
		if m != None:
			assert m >= 1
			assert not modint.has_been_set
			modint.mod = m
			modint.has_been_set = True
		assert modint.has_been_set
		self._v = v if 0 <= v < modint.mod else v % modint.mod

	def __add__(self, other):
		if isinstance(other, modint):
			res = self._v + other._v
			if res > modint.mod:
				res -= modint.mod
		else:
			res = self._v + other
		return modint(res)

	def __sub__(self, other):
		if isinstance(other, modint):
			res = self._v - other._v
			if res < 0:
				res += modint.mod
		else:
			res = self._v - other
		return modint(res)

	def __mul__(self, other):
		if isinstance(other, modint):
			return modint(self._v * other._v)
		else:
			return modint(self._v * other)

	def __floordiv__(self, other):
		if isinstance(other, modint):
			other = other._v
		inv = pow(other, -1, modint.mod)
		return modint(self._v * inv)

	def __pow__(self, other):
		assert isinstance(other, int) and other >= 0
		return modint(pow(self._v, other, modint.mod))

	def __radd__(self, other):
		return modint(self._v + other)

	def __rsub__(self, other):
		return modint(other - self._v)

	def __rmul__(self, other):
		return modint(self._v * other)

	def __rfloordiv__(self, other):
		inv = pow(self._v, -1, modint.mod)
		return modint(other * inv)

	def __iadd__(self, other):
		if isinstance(other, modint):
			self._v += other._v
			if self._v >= modint.mod:
				self._v -= modint.mod
		else:
			self._v += other
			if self._v < 0 or self._v >= modint.mod:
				self._v %= modint.mod
		return self

	def __isub__(self, other):
		if isinstance(other, modint):
			self._v -= other._v
			if self._v < 0:
				self._v += modint.mod
		else:
			self._v -= other
			if self._v < 0 or self._v >= modint.mod:
				self._v %= modint.mod
		return self

	def __imul__(self, other):
		if isinstance(other, modint):
			self._v *= other._v
		else:
			self._v *= other
		if self._v < 0 or self._v >= modint.mod:
			self._v %= modint.mod
		return self

	def __ifloordiv__(self, other):
		if isinstance(other, modint):
			other = other._v
		inv = pow(other, -1, modint.mod)
		self._v *= inv
		if self._v > modint.mod:
			self._v %= modint.mod
		return self

	def __ipow__(self, other):
		assert isinstance(other, int) and other >= 0
		self._v = pow(self._v, other, modint.mod)
		return self

	def __eq__(self, other):
		if isinstance(other, modint):
			return self._v == other._v
		else:
			if other < 0 or other >= modint.mod:
				other %= modint.mod
			return self._v == other

	def __ne__(self, other):
		if isinstance(other, modint):
			return self._v != other._v
		else:
			if other < 0 or other >= modint.mod:
				other %= modint.mod
			return self._v != other

	def __str__(self):
		return str(self._v)

	def __repr__(self):
		return str(self._v)

	def __int__(self):
		return self._v
n = int(input())
s = input()
t = input()
mod = 10 ** 9 + 7
ans = modint(0, m=mod)
if s[0] == t[0]:
	ans += 3
	i = 1
else:
	ans += 6
	i = 2
while i < n:
	if s[i - 1] != t[i - 1] and s[i] == t[i]:
		ans *= 1
	elif s[i] == t[i]:
		ans *= 2
	elif s[i - 1] != t[i - 1]:
		ans *= 3
		i += 1
	else:
		ans *= 2
		i += 1
	i += 1
print(ans)


n = int(input())
s1 = input()
s2 = input()
ans = 1
i = 1
mod = 1000000007
if s1[0] == s2[0]:
	ans = 3
	i = 1
else:
	ans = 6
	i = 2
while i < n:
	if s1[i - 1] == s2[i - 1]:
		if s1[i] == s2[i]:
			ans = ans * 2 % mod
			i += 1
			continue
		else:
			ans = ans * 2 % mod
			i += 2
			continue
	elif s1[i] == s2[i]:
		ans = ans * 1 % mod
		i += 1
		continue
	else:
		ans = ans * 3 % mod
		i += 2
		continue
print(ans)


import sys
read = sys.stdin.read
large_p = 10 ** 9 + 7

def main():
	n = int(input())
	s1 = tuple(input())
	s2 = tuple(input())
	s = []
	cnt = 0
	while cnt < n:
		if s1[cnt] == s2[cnt]:
			s.append(1)
		else:
			s.append(2)
			cnt += 1
		cnt += 1
	if s[0] == 2:
		ans = 6
	else:
		ans = 3
	for i1 in range(1, len(s)):
		if s[i1 - 1] == 1:
			ans *= 2
		elif s[i1] == 2:
			ans *= 3
		ans = ans % large_p
	print(ans)

def __starting_point():
	main()
__starting_point()


import sys
N = int(sys.stdin.readline())
S = ['', '']
S[0] = sys.stdin.readline().strip()
S[1] = sys.stdin.readline().strip()
mod = 10 ** 9 + 7
pre = [S[0][0], S[1][0]]
ans = 3
if S[0][0] != S[1][0]:
	ans *= 2
for i in range(1, N):
	if pre[0] == S[0][i] and pre[1] == S[1][i]:
		continue
	if pre[0] == pre[1]:
		ans *= 2
		ans %= mod
	elif S[0][i] == S[1][i]:
		ans *= 1
	else:
		ans *= 3
		ans %= mod
	pre[0] = S[0][i]
	pre[1] = S[1][i]
print(ans)


MOD = 10 ** 9 + 7
N = int(input())
S1 = input()
S2 = input()
ans = 1
i = 0
if S1[i] == S2[i]:
	ans *= 3
	prev = True
	i += 1
else:
	ans *= 6
	prev = False
	i += 2
while i < N:
	now = S1[i] == S2[i]
	if now:
		if prev:
			ans *= 2
			ans %= MOD
		else:
			pass
		i += 1
	else:
		if prev:
			ans *= 2
			ans %= MOD
		else:
			ans *= 3
			ans %= MOD
		i += 2
	prev = now
print(ans)


N = int(input())
S1 = list(input())
S2 = list(input())
out = 1
i = 0
while i < N:
	if i == 0:
		if S1[i] == S2[i]:
			out *= 3
			flg = 0
		else:
			out *= 6
			flg = 1
			i += 1
	elif flg == 0:
		if S1[i] == S2[i]:
			out *= 2
			flg = 0
		else:
			out *= 2
			i += 1
			flg = 1
	elif S1[i] == S2[i]:
		out *= 1
		flg = 0
	else:
		out *= 3
		flg = 1
		i += 1
	i += 1
print(out % 1000000007)


N = int(input())
s = input()
t = input()
mod = 10 ** 9 + 7
cur = 0
ans = 1
for (i, (x, y)) in enumerate(zip(s, t)):
	if cur == 1:
		cur = 2
		continue
	if x == y:
		if i == 0:
			ans = 3
		elif cur == 0:
			ans *= 2 % mod
		else:
			cur = 0
			continue
	elif i == 0:
		ans *= 6
		cur = 1
	elif cur == 0:
		ans *= 2
		ans %= mod
		cur = 1
	else:
		ans *= 3 % mod
		cur = 1
print(ans % mod)


n = int(input())
s = input()
t = input()
mod = 10 ** 9 + 7
ans = 1
if s[0] == t[0]:
	ans *= 3
	idx = 1
	flag = 0
else:
	ans *= 6
	idx = 2
	flag = 1
while idx < n:
	if s[idx] == t[idx]:
		if flag:
			idx += 1
		else:
			ans = ans * 2 % mod
			idx += 1
		flag = 0
	else:
		if flag:
			ans = ans * 3 % mod
		else:
			ans = ans * 2 % mod
		idx += 2
		flag = 1
print(ans)


n = int(input())
s1 = input()
s2 = input()
mod = 10 ** 9 + 7
if s1[0] == s2[0]:
	cnt = 3
	flag = 0
	i = 1
else:
	cnt = 6
	flag = 1
	i = 2
while i < n:
	if s1[i] == s2[i] and flag == 0:
		i += 1
		cnt *= 2
	elif s1[i] == s2[i] and flag == 1:
		i += 1
		flag = 0
	elif s1[i] != s2[i] and flag == 0:
		i += 2
		cnt *= 2
		flag = 1
	else:
		i += 2
		cnt *= 3
	cnt %= mod
print(cnt % mod)


n = int(input())
s1 = input()
s2 = input()
mod = 10 ** 9 + 7

def rle(string):
	rle_str = string[0]
	rle_cnt = 1
	ans_l = []
	for i in range(1, len(string)):
		if rle_str == string[i]:
			rle_cnt += 1
		else:
			ans_l.append([rle_str, rle_cnt])
			rle_str = string[i]
			rle_cnt = 1
	ans_l.append([rle_str, rle_cnt])
	return ans_l
rle_s = rle(s1)
if rle_s[0][1] == 1:
	ans = 3
	left = 1
elif rle_s[0][1] == 2:
	ans = 6
	left = 2
for (s, i) in rle_s[1:]:
	if left == 1 and i == 1:
		ans *= 2
	elif left == 1 and i == 2:
		ans *= 2
	elif left == 2 and i == 1:
		ans *= 1
	elif left == 2 and i == 2:
		ans *= 3
	left = i
print(ans % mod)


N = int(input())
S1 = input()
S2 = input()
mod = 10 ** 9 + 7
ans = 1
if S1[0] == S2[0]:
	ans *= 3
	ans %= mod
	idx = 1
else:
	ans *= 6
	ans %= mod
	idx = 2
while idx <= N - 1:
	if S1[idx] == S2[idx]:
		if S1[idx - 1] == S2[idx - 1]:
			ans *= 2
			ans %= mod
			idx += 1
		else:
			ans *= 1
			ans %= mod
			idx += 1
	elif S1[idx - 1] == S2[idx - 1]:
		ans *= 2
		ans %= mod
		idx += 2
	else:
		ans *= 3
		ans %= mod
		idx += 2
print(ans)


from collections import Counter
n = int(input())
S = input()
Do = Counter(S)
Ans = 0
i = 0
if Do[S[0]] == 1:
	Ans = 3
	i += 1
	sig = 1
else:
	Ans = 6
	i += 2
	sig = 2
while not i >= n:
	if Do[S[i]] == 1:
		if sig == 1:
			Ans *= 2
		else:
			Ans *= 1
		sig = 1
		i += 1
	else:
		if sig == 1:
			Ans *= 2
		else:
			Ans *= 3
		sig = 2
		i += 2
	Ans = Ans % (10 ** 9 + 7)
print(Ans)


n = int(input())
s1 = input()
s2 = input()
if s1[0] == s2[0]:
	a = 3
	l = 0
	v = True
else:
	a = 6
	l = 1
	v = False
mod = 10 ** 9 + 7

def mult_mod(x, y):
	return x * y % mod
while l + 1 < n:
	if v:
		if s1[l + 1] == s2[l + 1]:
			l += 1
			a = mult_mod(a, 2)
		else:
			l += 2
			a = mult_mod(a, 2)
			v = False
	elif s1[l + 1] == s2[l + 1]:
		l += 1
		v = True
	else:
		l += 2
		a = mult_mod(a, 3)
print(a % mod)


mod = 1000000007
n = int(input())
s = [input() for i in range(2)]
ans = 1
i = 0
while i < n:
	if s[0][i] == s[1][i]:
		if i == 0:
			ans *= 3
		elif s[0][i - 1] == s[1][i - 1]:
			ans *= 2
		i += 1
	else:
		if i == 0:
			ans *= 6
		elif s[0][i - 1] == s[1][i - 1]:
			ans *= 2
		else:
			ans *= 3
		i += 2
	ans %= mod
print(ans)


import sys
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians
sys.setrecursionlimit(10 ** 6)
INF = 10 ** 20
eps = 1e-20
MOD = 10 ** 9 + 7

def lcm(x, y):
	return x * y // gcd(x, y)

def lgcd(l):
	return reduce(gcd, l)

def llcm(l):
	return reduce(lcm, l)

def powmod(n, i, mod=MOD):
	return pow(n, mod - 1 + i, mod) if i < 0 else pow(n, i, mod)

def div2(x):
	return x.bit_length()

def div10(x):
	return len(str(x)) - (x == 0)

def intput():
	return int(input())

def mint():
	return map(int, input().split())

def lint():
	return list(map(int, input().split()))

def ilint():
	return (int(input()), list(map(int, input().split())))

def judge(x, l=['Yes', 'No']):
	print(l[0] if x else l[1])

def lprint(l, sep='\n'):
	for x in l:
		print(x, end=sep)

def ston(c, c0='a'):
	return ord(c) - ord(c0)

def ntos(x, c0='a'):
	return chr(x + ord(c0))

class counter(dict):

	def __init__(self, *args):
		super().__init__(args)

	def add(self, x, d=1):
		self.setdefault(x, 0)
		self[x] += d

	def list(self):
		l = []
		for k in self:
			l.extend([k] * self[k])
		return l

class comb:

	def __init__(self, n, mod=None):
		self.l = [1]
		self.n = n
		self.mod = mod

	def get(self, k):
		(l, n, mod) = (self.l, self.n, self.mod)
		k = n - k if k > n // 2 else k
		while len(l) <= k:
			i = len(l)
			l.append(l[i - 1] * (n + 1 - i) // i if mod == None else l[i - 1] * (n + 1 - i) * powmod(i, -1, mod) % mod)
		return l[k]

def pf(x, mode='counter'):
	C = counter()
	p = 2
	while x > 1:
		k = 0
		while x % p == 0:
			x //= p
			k += 1
		if k > 0:
			C.add(p, k)
		p = p + 2 - (p == 2) if p * p < x else x
	if mode == 'counter':
		return C
	S = set([1])
	for k in C:
		T = deepcopy(S)
		for x in T:
			for i in range(1, C[k] + 1):
				S.add(x * k ** i)
	if mode == 'set':
		return S
	if mode == 'list':
		return sorted(list(S))
N = intput()
S1 = input()
S2 = input()
i = 0
ans = 1
tmp = 0
same = [3, 2, 1]
diff = [6, 2, 3]
while i < N:
	if S1[i] == S2[i]:
		ans *= same[tmp]
		tmp = 1
		i += 1
	else:
		ans *= diff[tmp]
		tmp = 2
		i += 2
	ans %= MOD
print(ans)


N = int(input())
S1 = input()
S2 = input()
ans = 1
MOD = 10 ** 9 + 7
i = 0
flag = True
while i < N:
	if S1[i] == S2[i]:
		if i == 0:
			ans *= 3
		elif flag:
			ans *= 2
		i += 1
		flag = True
	else:
		if i == 0:
			ans *= 6
		elif flag:
			ans *= 2
		else:
			ans *= 3
		i += 2
		flag = False
	ans %= MOD
print(ans)


n = int(input())
s1 = list(input())
s2 = list(input())
ans = 0
if s1[0] == s2[0]:
	ans = 3
else:
	ans = 6
for i in range(n - 1):
	if s1[i] == s2[i]:
		ans *= 2
	elif s1[i] == s1[i + 1]:
		continue
	elif s1[i + 1] != s2[i + 1]:
		ans *= 3
	else:
		ans *= 1
print(ans % 1000000007)


import sys
from collections import deque, defaultdict, namedtuple
import heapq
from math import sqrt, factorial, gcd, ceil, atan, pi
from itertools import permutations

def input():
	return sys.stdin.readline().strip()
import string
import operator
import random
from bisect import bisect_left, bisect_right
from functools import lru_cache, reduce
MOD = int(1000000000.0) + 7
INF = float('inf')
sys.setrecursionlimit(int(10000000.0))

def solve():
	n = int(input())
	a = input()
	b = input()
	ans = 1
	i = 0
	f = -1
	while i < n:
		if a[i] != b[i]:
			if f == -1:
				ans *= 6
			elif f == 1:
				ans *= 3
			else:
				ans *= 2
			i += 2
			f = 1
		else:
			if f == -1:
				ans *= 3
			elif f == 0:
				ans *= 2
			i += 1
			f = 0
	print(ans % MOD)
T = 1
for case in range(1, T + 1):
	ans = solve()


N = int(input())
S = [list(input()) for _ in range(2)]
MOD = 1000000007
i = 0

def define(index):
	if S[0][index] == S[1][index]:
		return 1
	else:
		return 0
if define(i):
	ans = 3
	i += 1
	f_g = 1
else:
	ans = 6
	i += 2
	f_g = 0
while i < N:
	t_g = define(i)
	if f_g == 0 and t_g == 0:
		ans *= 3
		ans %= MOD
	elif not (f_g == 0 and t_g == 1):
		ans *= 2
		ans %= MOD
	if t_g == 1:
		i += 1
	else:
		i += 2
	f_g = t_g
print(ans % MOD)


MOD = pow(10, 9) + 7

def MODINV(n: int, MOD=MOD):
	return pow(n, MOD - 2, MOD)

def main():
	N = int(input())
	S1 = input()
	S2 = input()
	ans = 1
	i = 0
	M = (S1[-1] == S2[-1]) * N + (S1[-1] != S2[-1]) * (N - 1)
	for _ in range(N):
		if i >= M - 1:
			break
		s1 = S1[i]
		s2 = S2[i]
		if s1 == s2:
			ans *= 2
			i += 1
		else:
			if S1[i + 2] != S2[i + 2]:
				ans *= 3
			i += 2
		ans %= MOD
	if S1[0] == S2[0]:
		ans *= 3
	else:
		ans *= 6
	print(ans % MOD)

def __starting_point():
	main()
__starting_point()


mod = 1000000007
n = int(input())
s = input()
s2 = input()
a = [] if n > 1 else [1]
for i in range(n - 1):
	if i != 0 and s[i - 1] == s[i]:
		continue
	if s[i] == s[i + 1]:
		a.append(2)
		if i == n - 3:
			a.append(1)
	else:
		a.append(1)
		if i == n - 2:
			a.append(1)
ans = 3 if a[0] == 1 else 6
for i in range(len(a) - 1):
	(b, c) = a[i:i + 2]
	if b == 1:
		ans = ans * 2 % mod
	elif c == 2:
		ans = ans * 3 % mod
print(ans)


MOD = 10 ** 9 + 7
n = int(input())
s1 = input()
s2 = input()
if s1[0] == s2[0]:
	end = 1
	count = 1
	ans = 3
else:
	end = 0
	count = 2
	ans = 6
while count < n:
	if end == 1:
		if s1[count] == s2[count]:
			ans *= 2
			ans %= MOD
			count += 1
		else:
			ans *= 2
			ans %= MOD
			count += 2
			end = 0
	elif s1[count] == s2[count]:
		count += 1
		end = 1
	else:
		ans *= 3
		ans %= MOD
		count += 2
print(ans)


n = int(input())
s1 = input() + ' '
s2 = input() + ' '
mod = 10 ** 9 + 7
s = []
for i in range(n):
	if s1[i] == s2[i]:
		s.append(1)
		continue
	if s1[i] == s1[i + 1]:
		continue
	s.append(2)
dp = [0] * len(s)
dp[0] = 3 if s[0] == 1 else 6
for i in range(len(s) - 1):
	if s[i] == 1 and s[i + 1] == 1:
		dp[i + 1] = dp[i] * 2
	if s[i] == 1 and s[i + 1] == 2:
		dp[i + 1] = dp[i] * 2
	if s[i] == 2 and s[i + 1] == 1:
		dp[i + 1] = dp[i]
	if s[i] == 2 and s[i + 1] == 2:
		dp[i + 1] = dp[i] * 3
	dp[i + 1] %= mod
print(dp[-1])


MOD = 10 ** 9 + 7
N = int(input())
S1 = input().rstrip()
S2 = input().rstrip()
L = len(S1)
if L == 1:
	print(3)
	return
if S1[0] == S1[1]:
	dp = 6
	start = 2
	state = 0
else:
	dp = 3
	start = 1
	state = 1
i = start
while i < L - 1:
	if S1[i] == S1[i + 1]:
		if state == 0:
			dp *= 3
			dp %= MOD
		else:
			dp *= 2
			dp %= MOD
		state = 0
		i += 2
	else:
		if state == 1:
			dp *= 2
			dp %= MOD
		state = 1
		i += 1
if state == 1:
	dp *= 2
	dp %= MOD
print(dp)


N = int(input())
s1 = list(input())
s2 = list(input())
dp = [0] * N
if s1[0] == s2[0]:
	dp[0] = 3
else:
	dp[0] = 6
for i in range(1, N):
	if s1[i] == s2[i]:
		if s1[i - 1] == s2[i - 1]:
			dp[i] = 2 * dp[i - 1] % (10 ** 9 + 7)
		else:
			dp[i] = dp[i - 1]
	elif s1[i] == s1[i - 1]:
		dp[i] = dp[i - 1]
	elif s1[i - 1] != s2[i - 1]:
		dp[i] = 3 * dp[i - 1] % (10 ** 9 + 7)
	else:
		dp[i] = 2 * dp[i - 1] % (10 ** 9 + 7)
print(dp[N - 1])


import decimal
import itertools
import math
import functools
import bisect
import heapq
import random
from collections import Counter, deque, defaultdict
import time
mod = 1000000007

def lmi():
	return list(map(int, input().split()))

def main():
	N = int(input())
	S1 = input()
	S2 = input()
	prev = 0
	ans = 1
	next_skip = False
	for i in range(N):
		if next_skip:
			next_skip = False
			continue
		if S1[i] == S2[i]:
			ans *= 3 - prev
			prev = 1
		else:
			if prev == 1:
				ans *= 2
			elif prev == 2:
				ans *= 3
			else:
				ans *= 3 * 2
			prev = 2
			next_skip = True
	print(ans % mod)

def __starting_point():
	main()
__starting_point()


n = int(input())
mod = 10 ** 9 + 7
s = [list(input()) for _ in range(2)]
ans = 1
i = 0
while i < n:
	if s[1][i] == s[0][i]:
		if i == 0:
			ans *= 3
			i += 1
		else:
			if s[0][i - 1] == s[1][i - 1]:
				ans = ans * 2 % mod
			i += 1
	else:
		if i == 0:
			ans *= 6
		elif s[0][i - 1] == s[1][i - 1]:
			ans = ans * 2 % mod
		else:
			ans = ans * 3 % mod
		i += 2
print(ans)


from itertools import groupby
N = int(input())
s = input()
S = input()
mod = 10 ** 9 + 7
s = [len(list(j)) for (i, j) in groupby(s)]
ans = 3 * s[0]
for i in range(1, len(s)):
	if s[i - 1] == 1:
		ans *= 2
	elif s[i] == 2:
		ans *= 3
	ans %= mod
print(ans)


n = int(input())
s1 = input()
s2 = input()
domino = []
i = 0
while i < n:
	if s1[i] == s2[i]:
		domino.append('X')
		i += 1
	else:
		domino.append('Y')
		i += 2
cnt = 0
if domino[0] == 'X':
	cnt += 3
else:
	cnt += 6
if len(domino) == 1:
	print(cnt % (10 ** 9 + 7))
else:
	for i in range(1, len(domino)):
		if domino[i] == 'X':
			if domino[i - 1] == 'X':
				cnt *= 2
			else:
				cnt *= 1
		elif domino[i - 1] == 'X':
			cnt *= 2
		else:
			cnt *= 3
	print(cnt % (10 ** 9 + 7))


n = int(input())
S = [list(input()) for _ in range(2)]
mod = 1000000007
if S[0][0] == S[1][0]:
	ans = 3
	i = 1
	typ = '2x1'
else:
	ans = 6
	i = 2
	typ = '2x2'
while i < n:
	if S[0][i] == S[1][i]:
		if typ == '2x1':
			ans *= 2
		typ = '2x1'
		i += 1
	else:
		if typ == '2x1':
			ans *= 2
		else:
			ans *= 3
		typ = '2x2'
		i += 2
	ans %= mod
print(ans)


import sys
from heapq import heappush, heappop

def input():
	return sys.stdin.readline().rstrip()

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
mod = 10 ** 9 + 7

def main():
	n = ii()
	s = []
	s.append(input())
	s.append(input())
	if s[0][0] == s[1][0]:
		ans = 3
	else:
		ans = 6
	for i in range(1, n):
		if s[0][i - 1] == s[1][i - 1]:
			ans *= 2
			ans %= mod
		elif s[0][i] != s[0][i - 1] and s[1][i] != s[1][i - 1] and (s[0][i] != s[1][i]):
			ans *= 3
			ans %= mod
	print(ans)

def __starting_point():
	main()
__starting_point()


MOD = 10 ** 9 + 7
N = int(input())
S1 = input()
S2 = input()
l = []
res = 1
while res < N:
	if S1[res - 1] == S1[res]:
		l.append(2)
		res += 2
	else:
		l.append(1)
		res += 1
if res == N:
	l.append(1)
n = len(l)
if l[0] == 1:
	ans = 3
else:
	ans = 6
for i in range(1, n):
	if l[i] == 1 and l[i - 1] == 1:
		ans = ans * 2 % MOD
	elif l[i] == 2 and l[i - 1] == 1:
		ans = ans * 2 % MOD
	elif l[i] == 2 and l[i - 1] == 2:
		ans = ans * 3 % MOD
print(ans)


import sys
MOD = 1000000007
N = int(input())
S1 = input()
S2 = input()
pattern = []
pos = 0
if N == 1:
	print(3)
	return
while True:
	if S1[pos] != S1[pos + 1]:
		pattern.append(0)
		pos += 1
	else:
		pattern.append(1)
		pos += 2
	if pos == N - 1:
		pattern.append(0)
		break
	elif pos == N:
		break
if pattern[0] == 0:
	ans = 3
	now = 0
else:
	ans = 6
	now = 1
for i in range(1, len(pattern)):
	if pattern[i] == 0:
		if now == 0:
			ans *= 2
			ans = ans % MOD
		else:
			ans *= 1
			ans = ans % MOD
		now = 0
	else:
		if now == 0:
			ans *= 2
			ans = ans % MOD
		else:
			ans *= 3
			ans = ans % MOD
		now = 1
print(ans)


n = int(input())
s = [input() for _ in range(2)]
mod = 10 ** 9 + 7
tmp = 1
pos = 0
pre_state = -1
while pos < n:
	if s[0][pos] == s[1][pos]:
		if pos == 0:
			tmp *= 3
		elif pre_state == 0:
			tmp *= 2
		else:
			tmp *= 1
		pre_state = 0
		pos += 1
	else:
		if pos == 0:
			tmp *= 6
		elif pre_state == 0:
			tmp *= 2
		else:
			tmp *= 3
		pre_state = 1
		pos += 2
	tmp %= mod
print(tmp)


from math import ceil, floor, factorial, gcd, sqrt, log2, cos, sin, tan, acos, asin, atan, degrees, radians, pi, inf, comb
from itertools import accumulate, groupby, permutations, combinations, product, combinations_with_replacement
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import Queue, LifoQueue, PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(MAP())
n = INT()
s1 = input()
s2 = input()
ans = 3
i = 1
while i < n:
	if i == 1 or s1[i - 1] != s1[i - 2]:
		if i == n - 1 or s1[i] != s1[i + 1]:
			ans = ans * 2 % (10 ** 9 + 7)
			i += 1
		else:
			ans = ans * 2 % (10 ** 9 + 7)
			i += 2
	elif i == n - 1 or s1[i] != s1[i + 1]:
		ans = ans * 1 % (10 ** 9 + 7)
		i += 1
	else:
		ans = ans * 3 % (10 ** 9 + 7)
		i += 2
print(ans)


n = int(input())
s = input() + '@'
t = input() + '@'
mod = 10 ** 9 + 7
b = []
for i in range(n):
	if s[i] == s[i + 1]:
		continue
	b.append(s[i] == t[i])
if b[0]:
	ans = 3
else:
	ans = 6
for i in range(1, len(b)):
	if b[i]:
		if b[i - 1]:
			ans *= 2
	elif b[i - 1]:
		ans *= 2
	else:
		ans *= 3
print(ans % mod)


N = int(input())
S = [input() + '.', input() + ',']
mod = 10 ** 9 + 7
if N == 1:
	print(3)
	return
if S[0][0] == S[1][0]:
	i = 1
	ans = 3
else:
	i = 2
	ans = 6
while i < N:
	if S[0][i] == S[1][i]:
		if S[0][i - 1] == S[1][i - 1]:
			ans *= 2
		else:
			pass
		ans %= mod
		i += 1
	else:
		if S[0][i - 1] == S[1][i - 1]:
			ans *= 2
		else:
			ans *= 3
		ans %= mod
		i += 2
print(ans)


import sys

def input():
	return sys.stdin.readline().strip()

def input_int():
	return int(input())

def input_int_list():
	return [int(i) for i in input().split()]

def main():
	n = input_int()
	L1 = [None] + list(input()) + [None]
	L2 = [None] + list(input()) + [None]
	seq = []
	if L1[1] == L2[1]:
		L1[1] = L2[1] = '#'
		seq.append('X')
	elif L1[1] == L1[2]:
		L1[1] = L1[2] = L2[1] = L2[2] = '#'
		seq.append('Y')
	for i in range(1, n + 1):
		if L1[i] == '#':
			continue
		elif L1[i] == L2[i]:
			seq.append('X')
			L1[i] = '#'
		elif L1[i] == L1[i + 1]:
			seq.append('Y')
			L1[i] = L1[i + 1] = '#'
	if seq[0] == 'X':
		ans = 3
	elif seq[0] == 'Y':
		ans = 6
	for i in range(1, len(seq)):
		if seq[i - 1] == 'X':
			if seq[i] == 'X':
				ans *= 2
			elif seq[i] == 'Y':
				ans *= 2
		elif seq[i - 1] == 'Y':
			if seq[i] == 'X':
				ans *= 1
			elif seq[i] == 'Y':
				ans *= 3
		ans %= 1000000007
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


N = int(input())
S1 = list(input())
S2 = list(input())
MOD = 10 ** 9 + 7
if S1[0] == S2[0]:
	ans = 3
	i = 1
else:
	ans = 6
	i = 2
while i < N:
	(pre_s1, pre_s2) = (S1[i - 1], S2[i - 1])
	(s1, s2) = (S1[i], S2[i])
	if pre_s1 == pre_s2:
		ans *= 2
		ans %= MOD
		if s1 == s2:
			i += 1
		else:
			i += 2
	elif s1 == s2:
		i += 1
	else:
		ans *= 3
		ans %= MOD
		i += 2
print(ans)


N = int(input())
A = input()
B = input()
p = 1000000007
C = [1 if a == b else 0 for (a, b) in zip(A, B)]
if C[0] == 1:
	score = 3
	i = 1
else:
	score = 6
	i = 2
while i < N:
	if C[i] == 1:
		if C[i - 1] == 1:
			score *= 2
		i += 1
	else:
		if C[i - 1] == 0:
			score *= 3
		else:
			score *= 2
		i += 2
print(score % p)


N = int(input())
S_1 = input()
S_2 = input()
MOD = 10 ** 9 + 7
if N == 1:
	print(3)
	return
ans = 3 if S_1[0] == S_2[0] else 6
for i in range(1, N):
	if S_1[i - 1] == S_1[i]:
		continue
	if S_1[i - 1] == S_2[i - 1]:
		ans = ans * 2 % MOD
	elif S_1[i] != S_2[i]:
		ans = ans * 3 % MOD
print(ans)


from sys import stdin, setrecursionlimit
import bisect, collections, copy, heapq, itertools, math, string
setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 1000000007

def input():
	return stdin.readline().strip()

def main():
	n = int(input())
	s1 = input()
	s2 = input()
	ans = 1
	arrange = ''
	flag = False
	for (c1, c2) in zip(s1, s2):
		if c1 == c2:
			arrange += 't'
		elif flag:
			flag = False
		else:
			arrange += 'y'
			flag = True
	flag = True
	before = ''
	for c in arrange:
		if flag:
			if c == 'y':
				ans *= 6
			else:
				ans *= 3
			flag = False
		else:
			md = before + c
			if md == 'yy':
				ans *= 3
			elif md == 'yt':
				ans *= 1
			else:
				ans *= 2
		before = c
		ans %= MOD
	print(ans)
	return

def __starting_point():
	main()
__starting_point()


n = int(input())
s1 = input()
s2 = input()
ans = 1
mod = 10 ** 9 + 7
tmp = 3
i = 0
f = -1
while i < n:
	if s1[i] == s2[i]:
		if f == 1:
			tmp = 1
		elif f == 0:
			tmp = 2
		ans *= tmp
		ans %= mod
		f = 0
	else:
		if f == 1:
			tmp = 3
		elif f == 0:
			tmp = 2
		else:
			tmp = 6
		ans *= tmp
		ans %= mod
		i += 1
		f = 1
	i += 1
print(ans)


import sys
read = sys.stdin.read
readline = sys.stdin.readline
(n,) = map(int, readline().split())
s = input()
t = input()
MOD = 10 ** 9 + 7
v = 2
ans = 1
i = 0
while i < n:
	if s[i] == t[i]:
		i += 1
		if v == 0:
			ans *= 2
		if v == 2:
			ans *= 3
		v = 0
		ans %= MOD
	else:
		i += 2
		if v == 0:
			ans *= 2
		if v == 1:
			ans *= 3
		if v == 2:
			ans *= 6
		v = 1
		ans %= MOD
print(ans % MOD)


N = int(input())
grid = [input(), input()]
MOD = 10 ** 9 + 7
cnt = 3 if grid[0][0] == grid[1][0] else 6
for i in range(1, N):
	(a, b) = (grid[0][i - 1], grid[1][i - 1])
	(c, d) = (grid[0][i], grid[1][i])
	if a == b:
		cnt *= 2
	elif c != d and a != c:
		cnt *= 3
	cnt %= MOD
print(cnt)


def inputlist():
	return [int(j) for j in input().split()]
mod = 10 ** 9 + 7
N = int(input())
if N == 1:
	print(3)
	return
S1 = list(input())
S2 = list(input())
blocks = []
s = S1[0]
for i in range(1, N):
	if S1[i] == S1[i - 1]:
		s += S1[i]
	else:
		blocks.append(s)
		s = S1[i]
	if i == N - 1:
		blocks.append(s)
n = len(blocks)
last_blocks = [0] * n
for i in range(1, n):
	last_blocks[i] = len(blocks[i - 1])
ans = 1
for i in range(n):
	tmp = blocks[i]
	last_block = last_blocks[i]
	if last_block == 0:
		if len(tmp) == 1:
			ans *= 3
		else:
			ans *= 6
	if last_block == 1:
		ans *= 2
	if last_block == 2:
		if len(tmp) == 1:
			ans *= 1
		if len(tmp) == 2:
			ans *= 3
	ans %= mod
print(ans % mod)


n = int(input())
s = input()
t = input()
u = []
now = 0
while now < n:
	if s[now] == t[now]:
		u.append(0)
		now += 1
	else:
		u.append(1)
		now += 2
ans = 1
if u[0] == 1:
	ans = 6
else:
	ans = 3
for i in range(1, len(u)):
	if u[i - 1] == 1 and u[i] == 1:
		ans *= 3
	elif u[i - 1] == 1 and u[i] == 0:
		ans *= 1
	elif u[i - 1] == 0 and u[i] == 1:
		ans *= 2
	else:
		ans *= 2
	ans %= 10 ** 9 + 7
print(ans)


n = int(input())
s1 = input()
s2 = input()
mod = 10 ** 9 + 7
yoko = True
if s1[0] == s2[0]:
	ans = 3
	cur = 1
	yoko = False
else:
	ans = 6
	cur = 2
while cur < n:
	if s1[cur] == s2[cur]:
		ans *= 1 if yoko else 2
		ans %= mod
		cur += 1
		yoko = False
	else:
		ans *= 3 if yoko else 2
		ans %= mod
		cur += 2
		yoko = True
print(ans)


import math

def read_int():
	return int(input().strip())

def read_ints():
	return list(map(int, input().strip().split(' ')))

def solve():
	N = read_int()
	s1 = input()
	s2 = input()
	P = []
	modulo = 10 ** 9 + 7
	(H, V) = (0, 1)
	for i in range(N):
		if i > 0 and s2[i] == s2[i - 1]:
			P[-1] = H
		else:
			P.append(V)
	dp = []
	if P[0] == H:
		dp.append(6)
	else:
		dp.append(3)
	for i in range(1, len(P)):
		if P[i] == H and P[i - 1] == H:
			dp.append(3 * dp[i - 1])
		elif P[i] == H and P[i - 1] == V:
			dp.append(2 * dp[i - 1])
		elif P[i] == V and P[i - 1] == V:
			dp.append(2 * dp[i - 1])
		else:
			dp.append(dp[i - 1])
		dp[-1] %= modulo
	return dp[-1]

def __starting_point():
	print(solve())
__starting_point()


N = int(input())
S = [list(input()) for _ in range(2)]
prev = S[0][0] == S[1][0]
if prev:
	x = 3
	i = 1
else:
	x = 6
	i = 2
while i < N:
	nxt = S[0][i] == S[1][i]
	i += 1 if nxt else 2
	if prev and nxt:
		x *= 2
	elif prev:
		x *= 2
	elif nxt:
		x = x
	else:
		x *= 3
	prev = nxt
print(x % (10 ** 9 + 7))


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

def int1(x):
	return int(x) - 1

def II():
	return int(input())

def MI():
	return list(map(int, input().split()))

def MI1():
	return list(map(int1, input().split()))

def LI():
	return list(map(int, input().split()))

def LI1():
	return list(map(int1, input().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return input().strip('\n')

def MS():
	return input().split()

def LS():
	return list(input().strip('\n'))

def LLS(rows_number):
	return [LS() for _ in range(rows_number)]

def gen_matrix(h, w, init):
	return [[init] * w for _ in range(h)]
INF = float('inf')
from math import ceil, floor, log2, log, sqrt, gcd
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
from collections import deque, defaultdict
from pprint import pprint
from functools import reduce, lru_cache

def solve():
	N = II()
	S = LLS(2)
	MOD = 1000000007
	i = 0
	pre = 'N'
	ans = 1
	while i < N:
		(s, t) = (S[0][i], S[1][i])
		if s == t:
			if pre == 'N':
				ans = 3
			elif pre == 'H':
				ans = ans * 2 % MOD
			else:
				ans = ans
			i += 1
			pre = 'H'
		else:
			if pre == 'N':
				ans = 6
			elif pre == 'H':
				ans = ans * 2 % MOD
			else:
				ans = ans * 3 % MOD
			i += 2
			pre = 'V'
	print(ans)

def __starting_point():
	solve()
__starting_point()


n = int(input())
a = input()
b = input()
if a[0] == b[0]:
	c = 3
	i = 1
	d = 0
else:
	c = 6
	i = 2
	d = 1
while i < n:
	if a[i] == b[i]:
		if d == 0:
			c = c * 2 % (10 ** 9 + 7)
		else:
			d = 0
	else:
		i += 1
		if d == 0:
			c = c * 2 % (10 ** 9 + 7)
			d = 1
		else:
			c = c * 3 % (10 ** 9 + 7)
	i += 1
print(c)


n = int(input())
s1 = input()
a2 = input()
s = list(s1)
t = []
if len(s) == 1:
	print(3)
	return
if len(s) == 2:
	print(6)
	return
for i in range(1, len(s) - 1):
	if s[i] == s[i + 1] and s[i] != s[i - 1]:
		t.append(2)
	if s[i] != s[i + 1] and s[i] != s[i - 1]:
		t.append(1)
if s[0] == s[1]:
	t = [2] + t
else:
	t = [1] + t
if s[len(s) - 1] != s[len(s) - 2]:
	t.append(1)
if t[0] == 1:
	ans = 3
else:
	ans = 6
for i in range(1, len(t)):
	if t[i] == 1:
		if t[i - 1] == 1:
			ans *= 2
		else:
			ans *= 1
	if t[i] == 2:
		if t[i - 1] == 1:
			ans *= 2
		else:
			ans *= 3
print(ans % 1000000007)


N = int(input())
dominoes = tuple((tuple(input()) for _ in range(2)))
if N == 1:
	print(3)
	return
ans = 0
MOD = 10 ** 9 + 7
before_vertical = False
if dominoes[0][0] == dominoes[1][0]:
	ans += 3
	now = 1
	before_vertical = True
else:
	ans += 6
	now = 2
while now < N:
	if before_vertical:
		if dominoes[0][now] == dominoes[1][now]:
			ans *= 2
			now += 1
		else:
			ans *= 2
			now += 2
			before_vertical = False
	elif dominoes[0][now] == dominoes[1][now]:
		ans *= 1
		now += 1
		before_vertical = True
	else:
		ans *= 3
		now += 2
	ans %= MOD
print(ans)


MOD = 10 ** 9 + 7
N = int(input())
s1 = input()
s2 = input()
index = 0
ans = 0
tmp = 0
if N == 1:
	print(3)
	return
if s1[index] == s1[index + 1]:
	ans = 6
	tmp = 6
	index += 2
else:
	ans = 3
	tmp = 3
	index += 1
while index < N:
	if tmp == 3:
		if s1[index] == s2[index]:
			index += 1
			tmp = 3
			ans *= 2 % MOD
		else:
			index += 2
			ans *= 2 % MOD
			tmp = 6
	elif s1[index] == s2[index]:
		index += 1
		tmp = 3
	else:
		index += 2
		tmp = 6
		ans *= 3 % MOD
print(ans % MOD)


from collections import defaultdict
n = int(input())
s1 = input()
s2 = input()
ans = 0
mod = 10 ** 9 + 7
if s1[0] == s2[0]:
	i = 1
	ans += 3
	flag = False
else:
	i = 2
	ans += 6
	flag = True
while i < n:
	if flag:
		if s1[i] == s2[i]:
			flag = False
		else:
			ans *= 3 % mod
			i += 1
	else:
		ans *= 2 % mod
		if s1[i] != s2[i]:
			flag = True
			i += 1
	i += 1
print(ans % mod)


def resolve():
	mod = 1000000007
	N = int(input())
	S = [list(input()) for _ in range(2)]
	domino_directions = []
	for i in range(N):
		if S[0][i] == S[1][i]:
			domino_directions.append('|')
			continue
		if i + 1 < N:
			if S[0][i] == S[0][i + 1]:
				domino_directions.append('-')
				i += 1
	ans = 3 if domino_directions[0] == '|' else 6
	for i in range(1, N):
		pair = ''.join(domino_directions[i - 1:i + 1])
		if pair == '||' or pair == '|-':
			ans *= 2
		elif pair == '--':
			ans *= 3
		if ans > mod:
			ans %= mod
	print(ans)
resolve()


MOD = 1000000007
N = int(input())
S1 = input()
S2 = input()
ans = 1
idx = 0
if S1[idx] == S2[idx]:
	ans *= 3
	idx += 1
else:
	ans *= 6
	idx += 2
while idx < N:
	if S1[idx] == S2[idx]:
		if S1[idx - 1] == S2[idx - 1]:
			ans *= 2
		idx += 1
	else:
		if S1[idx - 1] == S2[idx - 1]:
			ans *= 2
		else:
			ans *= 3
		idx += 2
ans %= MOD
print(ans)


import sys
input = sys.stdin.readline
N = int(input())
S1 = input().strip()
S2 = input().strip()
mod = 10 ** 9 + 7
ans = 1
prev = ''
for i in range(N):
	if i == 0:
		ans *= 3
		if S1[i] != S2[i]:
			ans *= 2
	elif S1[i - 1] == S1[i]:
		pass
	elif S1[i - 1] == S2[i - 1]:
		ans *= 2
		ans %= mod
	elif S1[i] == S2[i]:
		pass
	else:
		ans *= 3
		ans %= mod
print(ans)


def resolve():
	MOD = 10 ** 9 + 7
	N = int(input())
	S = input()
	T = input()
	i = 0
	ans = 0
	flag = 1
	if S[i] == T[i]:
		ans = 3
		i += 1
		flag = 1
	else:
		ans = 6
		i += 2
		flag = 2
	while i < N:
		if S[i] == T[i]:
			if flag == 1:
				ans *= 2
				ans %= MOD
			i += 1
			flag = 1
		else:
			if flag == 1:
				ans *= 2
				ans %= MOD
			else:
				ans *= 3
				ans %= MOD
			i += 2
			flag = 2
	print(ans)

def __starting_point():
	resolve()
__starting_point()


import sys
readline = sys.stdin.readline
N = int(readline())
S = readline().rstrip()
if N == 1:
	print(3)
	return
DIV = 1000000007
ind = 0
ans = 1
tate = False
if S[ind] == S[ind + 1]:
	ans *= 6
	ind += 2
	tate = False
else:
	ans *= 3
	ind += 1
	tate = True
while ind < N:
	if ind + 1 == N or S[ind] != S[ind + 1]:
		if tate:
			ans *= 2
		else:
			ans *= 1
		ans %= DIV
		tate = True
		ind += 1
	else:
		if tate:
			ans *= 2
		else:
			ans *= 3
		ans %= DIV
		tate = False
		ind += 2
print(ans)


MOD = 10 ** 9 + 7
N = int(input())
s1 = input()
s2 = input()
result = 1
s_index = 0
if s1[s_index] == s2[s_index]:
	result *= 3
	s_index += 1
	prev_verticalp = True
else:
	result *= 6
	s_index += 2
	prev_verticalp = False
while s_index < N:
	if prev_verticalp:
		if s1[s_index] == s2[s_index]:
			result = result * 2 % MOD
			s_index += 1
			prev_verticalp = True
		else:
			result = result * 2 % MOD
			s_index += 2
			prev_verticalp = False
	elif s1[s_index] == s2[s_index]:
		s_index += 1
		prev_verticalp = True
	else:
		result = result * 3 % MOD
		s_index += 2
		prev_verticalp = False
print(result)


(N, S, T) = open(0)
ans = 3
i = 1
if S[0] != T[0]:
	ans *= 2
	i *= 2
while i < int(N):
	if S[i - 1] == T[i - 1]:
		ans *= 2
	elif S[i] != T[i]:
		ans *= 3
	i += 1 + (S[i] != T[i])
print(ans % (10 ** 9 + 7))


N = int(input())
S = [input() for i in range(2)]
MOD = 1000000007
ans = 1
prev = ''
i = 0
while i < N:
	if S[0][i] == S[1][i]:
		if prev == '|':
			ans *= 2
		elif prev == '-':
			ans *= 1
		else:
			ans *= 3
		prev = '|'
		i += 1
	else:
		if prev == '|':
			ans *= 2
		elif prev == '-':
			ans *= 3
		else:
			ans *= 6
		prev = '-'
		i += 2
	ans %= MOD
print(ans)


def main():
	N = int(input())
	S = []
	S.append(input())
	S.append(input())
	MOD = 10 ** 9 + 7
	ans = 1
	pre_mino_flag = -1
	pass_flag = False
	if S[0][0] == S[1][0]:
		ans *= 3
		pre_mino_flag = 0
	else:
		ans *= 6
		pre_mino_flag = 1
		pass_flag = True
	for i in range(1, N):
		if pass_flag:
			pass_flag = False
			continue
		if S[0][i] == S[1][i]:
			if pre_mino_flag == 0:
				ans *= 2
				ans %= MOD
			else:
				pass
			pre_mino_flag = 0
		else:
			pass_flag = True
			if pre_mino_flag == 0:
				ans *= 2
				ans %= MOD
			else:
				ans *= 3
				ans %= MOD
			pre_mino_flag = 1
	print(ans)

def __starting_point():
	main()
__starting_point()


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
MOD = 1000000007

def I():
	return int(input())

def F():
	return float(input())

def SS():
	return input()

def LI():
	return [int(x) for x in input().split()]

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LSS():
	return input().split()

def resolve():
	N = I()
	S = [SS() for _ in range(2)]
	t = []
	i = 0
	if N == 1:
		t.append('v')
	else:
		while i + 1 < N:
			if S[0][i] == S[0][i + 1]:
				t.append('h')
				i += 2
			else:
				t.append('v')
				i += 1
		if S[0][-2] != S[0][-1]:
			t.append('v')
	ans = 1
	if t[0] == 'h':
		ans *= 6
	else:
		ans *= 3
	ans %= MOD
	for i in range(len(t) - 1):
		if t[i] == 'h':
			if t[i + 1] == 'h':
				ans *= 3
			else:
				ans *= 1
		elif t[i + 1] == 'h':
			ans *= 2
		else:
			ans *= 2
		ans %= MOD
	print(ans)

def __starting_point():
	resolve()
__starting_point()


N = int(input())
S = [input() for _ in range(2)]
types = []
i = 0
while i < N:
	if S[0][i] == S[1][i]:
		types.append(1)
		i += 1
	else:
		types.append(2)
		i += 2
MOD = 10 ** 9 + 7
if types[0] == 1:
	ans = 3
else:
	ans = 6
for i in range(1, len(types)):
	if types[i] == 1 and types[i - 1] == 1:
		ans *= 2
	elif types[i] == 1 and types[i - 1] == 2:
		ans *= 1
	elif types[i] == 2 and types[i - 1] == 1:
		ans *= 2
	elif types[i] == 2 and types[i - 1] == 2:
		ans *= 3
	ans %= MOD
print(ans % MOD)


N = int(input())
S1 = input()
S2 = input()
mod = 1000000007
i = 0
array = []
while i < N:
	if S1[i] == S2[i]:
		array.append(0)
		i += 1
	else:
		array.append(1)
		i += 2
for i in range(len(array)):
	if i == 0:
		if array[i] == 0:
			ans = 3
		else:
			ans = 6
	elif array[i] == 0:
		if array[i - 1] == 0:
			ans = ans * 2
	elif array[i - 1] == 0:
		ans = ans * 2
	else:
		ans = ans * 3
	ans = ans % mod
print(ans)


N = int(input())
s1 = list(input())
s2 = list(input())
s = list(zip(s1, s2))
ss = []
skip = 0
for i in s:
	if skip:
		skip = 0
		continue
	if i[0] != i[1]:
		skip = 1
	ss.append(i)
mod = 10 ** 9 + 7
ans = 1
if ss[0][0] == ss[0][1]:
	f = 1
	ans *= 3
else:
	f = 0
	ans *= 6
for i in range(1, len(ss)):
	if ss[i][0] == ss[i][1]:
		nf = 1
	else:
		nf = 0
	if f:
		ans *= 2
	elif not nf:
		ans *= 3
	ans %= mod
	f = nf
print(ans)


n = int(input())
s1 = input()
s2 = input()
MOD = 10 ** 9 + 7
for (i, (a, b)) in enumerate(zip(s1, s2)):
	if i == 0:
		if a != b:
			dp = 6
		else:
			dp = 3
		prev = (a, b)
	elif prev[0] == a and prev[1] == b:
		continue
	elif a == b:
		if prev[0] == prev[1]:
			dp *= 2
			dp %= MOD
			prev = (a, b)
		else:
			prev = (a, b)
	elif prev[0] == prev[1]:
		dp *= 2
		dp %= MOD
		prev = (a, b)
	else:
		dp *= 3
		dp %= MOD
		prev = (a, b)
print(dp)


N = int(input())
s1 = input()
s2 = input()
ans = 0
mod = 10 ** 9 + 7
if s1[0] == s2[0]:
	i = 1
	ans += 3
	dual = False
else:
	i = 2
	ans += 6
	dual = True
while i < N:
	if dual:
		if s1[i] == s2[i]:
			dual = False
		else:
			ans *= 3
			ans %= mod
			i += 1
	else:
		ans *= 2
		ans %= mod
		if s1[i] != s2[i]:
			dual = True
			i += 1
	i += 1
print(ans % mod)


n = int(input())
x = input()
y = input()
now = 1
flag = 0
i = 0
while i < n:
	if i == 0:
		if x[i] == y[i]:
			now *= 3
			flag = 1
			i += 1
		else:
			now *= 6
			flag = 0
			i += 2
	elif x[i] == y[i]:
		if flag == 0:
			flag = 1
			i += 1
		else:
			now *= 2
			now = now % 1000000007
			flag = 1
			i += 1
	elif flag == 0:
		now *= 3
		now = now % 1000000007
		i += 2
		flag = 0
	else:
		now *= 2
		now = now % 1000000007
		i += 2
		flag = 0
print(now)


def solve():

	def dfs(p, prea, preb):
		if p == n:
			return 1
		if (p, prea, preb) in dp:
			return dp[p, prea, preb]
		ret = 0
		if s1[p] == s2[p]:
			for i in range(3):
				if i != prea and i != preb:
					ret += dfs(p + 1, i, i)
		else:
			for i in range(3):
				for j in range(3):
					if i != j and i != prea and (j != preb):
						ret += dfs(p + 2, i, j)
		ret %= mod
		dp[p, prea, preb] = ret
		return ret
	n = int(input())
	s1 = input()
	s2 = input()
	mod = 10 ** 9 + 7
	dp = {}
	print(dfs(0, -1, -1))
solve()


n = int(input())
s1 = input()
s2 = input()
k = 1
i = 0
if s1[0] == s2[0]:
	i += 1
	k = 3
else:
	i += 2
	k = 6
mod = 1000000007
while i < n:
	if s1[i] != s2[i] and s1[i - 1] != s2[i - 1]:
		k *= 3
		i += 2
	elif s1[i] != s2[i] and s1[i - 1] == s2[i - 1]:
		k *= 2
		i += 2
	else:
		if s1[i - 1] == s2[i - 1]:
			k *= 2
		i += 1
	k %= mod
print(k)


N = int(input())
S1 = input()
S2 = input()
ans = 0
tate = True
if S1[0] == S2[0]:
	ans = 3
	tate = True
	i = 1
else:
	ans = 6
	tate = False
	i = 2
while i < N:
	if S1[i] == S2[i]:
		if tate:
			ans *= 2
		i += 1
		tate = True
	else:
		if tate:
			ans *= 2
		else:
			ans *= 3
		i += 2
		tate = False
	ans %= 1000000007
print(ans)


import sys
import os
from copy import copy
import operator
import time
import datetime
import math
from math import floor, ceil, sqrt, log
import statistics
from statistics import mean, median
from decimal import Decimal as D
from fractions import Fraction as F
import functools
import random
from random import randint, shuffle
import bisect
import string
from collections import deque
import collections
import itertools
import heapq
sys.setrecursionlimit(4100000)
product = functools.partial(functools.reduce, operator.mul)
INF = float('inf')

class UnionFind:

	def __init__(self, n):
		self.parents = [-1] * n

	def union(self, x, y):
		(x, y) = (self.find(x), self.find(y))
		if x != y:
			if self.parents[x] > self.parents[y]:
				(x, y) = (y, x)
			self.parents[x] += self.parents[y]
			self.parents[y] = x

	def find(self, x):
		if self.parents[x] < 0:
			return x
		self.parents[x] = self.find(self.parents[x])
		return self.parents[x]

	def size(self, x):
		return -self.parents[self.find(x)]

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def members(self, x):
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i) == root]

	def roots(self):
		return list(filter(lambda x: x < 0, self.parents))

	def group_count(self):
		return len(self.roots())

	def max_size(self):
		return -min(self.parents)

	def min_size(self):
		return -max(self.roots())

	def append(self, n):
		self.parents += [-1] * n

class Imos:

	def __init__(self, n):
		self.val = [0] * n

	def add(self, x, y, n=None):
		if n is None:
			n = 1
		self.val[x] += n
		if len(self.val) > y + 1:
			self.val[y + 1] -= n

	def imos(self):
		for i in range(1, len(self.val)):
			self.val[i] += self.val[i - 1]

	def max(self):
		return max(self.val)

	def min(self):
		return min(self.val)

class CS:

	def __init__(self, grid):
		self.cs = grid
		for i0 in range(len(grid)):
			for i1 in range(len(grid[0])):
				if i0 == 0:
					if i1 == 0:
						continue
					self.cs[i0][i1] += self.cs[i0][i1 - 1]
				elif i1 == 0:
					self.cs[i0][i1] += self.cs[i0 - 1][i1]
				else:
					self.cs[i0][i1] += self.cs[i0 - 1][i1] + self.cs[i0][i1 - 1] - self.cs[i0 - 1][i1 - 1]

	def sum(self, start_0, start_1, end_0, end_1):
		if start_0 == 0:
			if start_1 == 0:
				return self.cs[end_0][end_1]
			return self.cs[end_0][end_1] - self.cs[end_0][start_1 - 1]
		if start_1 == 0:
			return self.cs[end_0][end_1] - self.cs[start_0 - 1][end_1]
		start_0 -= 1
		start_1 -= 1
		return self.cs[end_0][end_1] - self.cs[start_0][end_1] - self.cs[end_0][start_1] + self.cs[start_0][start_1]

def mod(n):
	return n % (10 ** 9 + 7)

def sinput():
	return sys.stdin.readline()[:-1]

def input():
	inputs = list(map(int, sys.stdin.readline().split()))
	if len(inputs) == 1:
		return inputs[0]
	return inputs

def listban(l):
	return list(map(list, set(map(tuple, l))))

def div(n):
	(lower_divisors, upper_divisors) = ([], [])
	i = 1
	while i * i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n // i)
		i += 1
	return lower_divisors + upper_divisors[::-1]

def prime(n):
	a = []
	while n % 2 == 0:
		a.append(2)
		n //= 2
	f = 3
	while f * f <= n:
		if n % f == 0:
			a.append(f)
			n //= f
		else:
			f += 2
	if n != 1:
		a.append(n)
	return a

def div_counter(l, n):
	return prime(l).count(n)

def lcm(x, y):
	return x * y // math.gcd(x, y)

def C(n, r):
	if n < r:
		return 0
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def P(n, r):
	if n < r:
		return 0
	return math.factorial(n) // math.factorial(n - r)

def H(n, r):
	return C(n + r - 1, r)

def cos(x, y, a):
	return (x ** 2 + y ** 2 - 2 * x * y * math.cos(math.radians(a))) ** 0.5

def DFS(g, s, pos=None):
	if pos is None:
		pos = set()
	pos.add(s)
	for i in g[s]:
		if not i in pos:
			DFS(g, i, pos)
	return pos

def DFS_one(g, s, pos=None):
	if pos is None:
		pos = set()
	pos = copy(pos)
	pos.add(s)
	b = copy(pos)
	m = copy(pos)
	for i in g[s]:
		if not i in pos:
			b = DFS(g, i, pos)
			if len(m) < len(b):
				m = b
	return m

def BFS(g, q, pos=None):
	if pos is None:
		pos = set()
	if type(q) == deque:
		pos.add(q)
		q = deque([q])
	pos.add(q[-1])
	for i in g[q.pop()]:
		if not i in pos:
			q.append(i)
	while q != deque():
		(pos, q) = BFS(g, q, pos)
	return (pos, q)

def SSP(a, li=None):
	if li is None:
		li = []
	if len(a) == 1:
		return [a[0]]
	return list(set(li + SSP(a[1:], li) + list(map(lambda x: x + a[0], SSP(a[1:], li))) + [a[0]]))

def dijkstra(g, s):
	n = len(g)
	dist = [10 ** 100] * n
	hq = [(0, s)]
	dist[s] = 0
	seen = [False] * n
	while hq:
		v = heapq.heappop(hq)[1]
		seen[v] = True
		for (to, cost) in g[v]:
			if seen[to] == False and dist[v] + cost < dist[to]:
				dist[to] = dist[v] + cost
				heapq.heappush(hq, (dist[to], to))
	return dist

def LIS(b):
	l = [b[0]]
	for i in b:
		if i > l[-1]:
			l += [i]
		else:
			l[bisect.bisect_left(l, i)] = i
	return len(l)

def two(n):
	return len(str(bin(n))) - str(bin(n)).rfind('1') - 1

def yn(b):
	if b:
		print('Yes')
	else:
		print('No')

def op(s):
	print(s)
	return
n = input()
s = [sinput()]
s += [sinput()]
skip = False
na = [0] * n
ans = 1
for i in range(n):
	if skip:
		skip = False
		continue
	if s[0][i] == s[1][i]:
		if na[i - 1] == 0:
			ans *= 3
			ans %= 1000000007
		elif na[i - 1] == 1:
			ans *= 2
			ans %= 1000000007
		na[i] = 1
	else:
		if na[i - 1] == 0:
			ans *= 6
			ans %= 1000000007
		elif na[i - 1] == 1:
			ans *= 2
			ans %= 1000000007
		elif na[i - 1] == 2:
			ans *= 3
			ans %= 1000000007
		na[i] = 2
		na[i + 1] = 2
		skip = True
print(ans)


n = int(input())
s1 = input()
s2 = input()
cnt = []
cnt2 = 0
for i in range(n):
	if cnt2 >= n:
		break
	if s1[cnt2] == s2[cnt2]:
		cnt2 += 1
		cnt.append(1)
	else:
		cnt2 += 2
		cnt.append(2)
if cnt[0] == 1:
	ans = 3
else:
	ans = 6
mod = 10 ** 9 + 7
for i in range(1, len(cnt)):
	if cnt[i - 1] == 1:
		ans *= 2
	elif cnt[i - 1] == 2 and cnt[i] == 2:
		ans *= 3
	ans %= mod
print(ans)


N = int(input())
S1 = input()
S2 = input()
if S1[0] == S2[0]:
	ans = 3
	t = 1
else:
	ans = 6
	t = 2
for i in range(1, N):
	if S1[i] == S1[i - 1]:
		continue
	if S1[i] == S2[i]:
		if t == 1:
			ans *= 2
		t = 1
	else:
		if t == 1:
			ans *= 2
		else:
			ans *= 3
		t = 2
	ans %= 10 ** 9 + 7
print(ans)


N = int(input())
S1 = str(input())
S2 = str(input())
if S1[0] == S2[0]:
	ans = 3
	cnt = 1
	tmp = 0
else:
	ans = 6
	cnt = 2
	tmp = 1
while cnt < N:
	if tmp == 0:
		if S1[cnt] == S2[cnt]:
			ans *= 2
			cnt += 1
		else:
			ans *= 2
			cnt += 2
			tmp = 1
	elif S1[cnt] == S2[cnt]:
		cnt += 1
		tmp = 0
	else:
		ans *= 3
		cnt += 2
print(ans % 1000000007)


n = int(input())
s1 = input()
s2 = input()
mod = 10 ** 9 + 7
ans = 1
i = 0
prev = 'None'
while i < n:
	if s1[i] == s2[i]:
		if prev == 'None':
			ans = 3
		elif prev == 'X':
			ans = ans * 2 % mod
		else:
			pass
		i += 1
		prev = 'X'
	else:
		if prev == 'None':
			ans = 6
		elif prev == 'X':
			ans = ans * 2 % mod
		else:
			ans = ans * 3 % mod
		i += 2
		prev = 'Y'
print(ans)


def resolve():
	N = int(input())
	S1 = list(input())
	S2 = list(input())
	mod = 10 ** 9 + 7
	if S1[0] == S2[0]:
		ans = 3
		now = 0
		ct = 1
	else:
		ans = 6
		now = 1
		ct = 2
	while ct < N:
		if S1[ct] == S2[ct]:
			if now == 0:
				ans *= 2
				ans %= mod
			else:
				pass
			now = 0
			ct += 1
		else:
			if now == 0:
				ans *= 2
				ans %= mod
			else:
				ans *= 3
				ans %= mod
			now = 1
			ct += 2
	print(ans)
resolve()


N = int(input())
Mod = 10 ** 9 + 7
S = input()
T = input()
if S[0] == T[0]:
	(K, I) = (3, 1)
	Mode = True
else:
	(K, I) = (6, 2)
	Mode = False
while I < N:
	if S[I] == T[I]:
		if Mode:
			K *= 2
		else:
			K *= 1
		Mode = True
		I += 1
	else:
		if Mode:
			K *= 2
		else:
			K *= 3
		Mode = False
		I += 2
	K %= Mod
print(K)


n = int(input())
k = [input(), input()]
rt = 1
i = 0
pre = 0
mods = 1000000007
while i < n:
	if i > 0:
		if k[0][i] == k[1][i]:
			if pre:
				rt *= 2
			pre = 1
			i += 1
		else:
			if pre:
				rt *= 2
			else:
				rt *= 3
			pre = 0
			i += 2
	elif k[0][i] == k[1][i]:
		rt *= 3
		pre = 1
		i += 1
	else:
		rt *= 6
		pre = 0
		i += 2
	rt %= mods
print(rt)


N = int(input())
S1 = input()
S2 = input()
m1 = ''
m = 10 ** 9 + 7
S1 += '.'
for i in range(len(S1) - 1):
	if S1[i] == S1[i + 1]:
		m1 += 'y'
	else:
		m1 += 't'
m1 = m1.replace('yt', 'y')
score = [1] * len(m1)
for i in range(1, len(m1)):
	if m1[i - 1] == 't' and m1[i] == 't':
		score[i] = 2
	elif m1[i - 1] == 'y' and m1[i] == 't':
		score[i] = 1
	elif m1[i - 1] == 't' and m1[i] == 'y':
		score[i] = 2
	elif m1[i - 1] == 'y' and m1[i] == 'y':
		score[i] = 3
if m1[0] == 'y':
	score[0] = 6
else:
	score[0] = 3
ans = 1
for i in range(len(m1)):
	ans = ans * score[i] % m
print(ans)


n = int(input())
s = input()
t = input()
prev = -1
i = 0
ans = 1
mod = pow(10, 9) + 7
while i != n:
	if s[i] == t[i]:
		if prev == -1:
			ans *= 3
		elif prev == 0:
			ans *= 2
		prev = 0
		i += 1
	else:
		if prev == -1:
			ans *= 6
		elif prev == 0:
			ans *= 2
		else:
			ans *= 3
		prev = 1
		i += 2
	ans %= mod
print(ans)