{-# LANGUAGE CPP #-}
#define MOD (1000000007 :: Integer)

import Prelude hiding (mod)

mod :: Integer -> Integer -> Integer
mod x y
  | x >= y    = mod (x - y) y
  | otherwise = x

calc' :: String -> Integer
calc' [x] = 3
calc' [x,y] = 6
calc' (x:y:xs)
  | x == y  = 6 * calc (x:y:xs)
  | x /= y  = 3 * calc (x:y:xs)

calc :: String -> Integer 
calc [x,y] = 1
calc [x,y,z]
  | x == y    = 1
  | y == z    = 2
  | otherwise = 4
calc (x:y:z:w:xs)
  | x == y && z == w  = 3 * calc(z:w:xs) `mod` MOD
  | x == y && z /= w  = calc(z:w:xs) `mod` MOD
  | x /= y && y == z  = 2 * calc(y:z:w:xs) `mod` MOD
  | x /= y            = 2 * calc(y:z:w:xs) `mod` MOD

main :: IO ()
main = do
  getLine
  str <- getLine
  getLine
  putStrLn . show . calc' $ str
