{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Data.Foldable (toList)
import           Data.List     (group)
import           Data.Sequence ((|>))
import qualified Data.Sequence as Seq

data Direction = V | H deriving (Show, Eq)

main :: IO ()
main = do
  n <- readLn
  s1 <- getLine
  s2 <- getLine
  print $ solve n s1 s2

solve :: Int -> String -> String -> Int
solve n s1 _ = foldr1 mulMod cs where
  cs = f (head bs) : map g (windows 2 bs)
  bs = map h $ group s1
  f V = 3
  f H = 6
  g [V, V] = 2
  g [V, H] = 2
  g [H, V] = 1
  g [H, H] = 3
  h xs = if length xs == 1 then V else H

mulMod :: Int -> Int -> Int
mulMod a b = (a * b) `mod` m

m :: Int
m = 10^9 + 7

-- https://stackoverflow.com/questions/27726739/implementing-an-efficient-sliding-window-algorithm-in-haskell
windows :: Int -> [a] -> [[a]]
windows n0 = go 0 Seq.empty where
  go n s (a:as)
    | n' <  n0  =              go n' s'  as
    | n' == n0  = toList s'  : go n' s'  as
    | otherwise = toList s'' : go n  s'' as where
        n'  = n + 1
        s'  = s |> a
        s'' = Seq.drop 1 s'
  go _ _ [] = []
