{-# LANGUAGE BangPatterns #-}
import Control.Applicative((<$>))
import Control.Monad
import qualified Data.Map as M
import qualified Data.List as L
readInt    = read :: String -> Int
readFloat  = read :: String -> Float
getInt     = readInt <$> getLine
getIntList = map readInt . words <$> getLine

main :: IO ()
main = do
  n  <- getInt
  s1 <- getLine
  s2 <- getLine
  print $ (solve Initial s1 s2 1) `mod` 1000000007

data Status = Initial | Tate | Yoko deriving Show

solve :: Status -> String -> String -> Int -> Int
solve Tate [x] [y] cur = cur*2
solve Yoko [x] [y] cur = cur
solve Initial [x] [y] cur = cur*3
solve s (x:x':xs) (y:y':ys) !cur
  | x == y    =
    case s of
      Initial -> solve Tate (x':xs) (y':ys) ((cur*3)`mod` 1000000007)
      Tate    -> solve Tate (x':xs) (y':ys) ((cur*2)`mod` 1000000007)
      Yoko    -> solve Tate (x':xs) (y':ys) ((cur)`mod` 1000000007)
  | otherwise =
    case s of
      Initial -> solve Yoko xs ys cur*6
      Tate    -> solve Yoko xs ys cur*2
      Yoko    -> solve Yoko xs ys cur*3