module Main where
import Data.List

int = read::String -> Int
main = interact $ printer . solver . parser

printer = unlines . (:[]) . show
parser = words

solver :: [String] -> Int
solver [ns, (s11:s1s), (s21:s2s)] = result
  where
    n = int ns
    result = 
      if s11==s21 
      then sweep (s11:s1s) (s21:s2s) 3
      else sweep (s1s) (s2s) 6

sweep (s11:[]) (s21:[]) pattern = pattern
sweep (s11:s12:s1s) (s21:s22:s2s) pattern
  | s11 == s21 && s12 == s22 = sweep (s12:s1s) (s22:s2s) (mod (2*pattern) 1000000007 )
  | s11 == s21 && s12 /= s22 = sweep (s1s) (s2s) (mod (2*pattern) 1000000007 )
  | s11 /= s21 && s12 == s22 = sweep (s12:s1s) (s22:s2s) (pattern)
  | s11 /= s21 && s12 /= s22 = sweep (s1s) (s2s) (mod (3*pattern) 1000000007 )
  
