data Arrange = Twin | Single deriving (Show, Eq)

prime = 1000000007 :: Integer

abbr :: String -> [Arrange] -> [Arrange]
abbr [] xs = xs
abbr [_] xs = Single:xs
abbr (x:y:ys) xs
  | x == y = abbr ys (Twin:xs)
  | x /= y = abbr (y:ys) (Single:xs) 

(*->) :: Arrange -> Arrange -> Integer
pre *-> cur
  | pre == Twin && cur == Twin = 3
  | pre == Twin && cur == Single = 1
  | pre == Single && cur == Twin = 2
  | otherwise = 2
infixl 7 *->

solve :: [Arrange] -> Arrange -> Integer
solve [] _ = 1
solve (cur:xs) pre = pre *-> cur * (solve xs cur) `mod` prime

main = do
  getLine
  getLine
  str <- getLine
  let (x:xs) = reverse $ abbr str []
  case xs of
    [] -> print 3
    _ -> print $ if x == Twin then 6 else 3 * solve xs x
