data Direction = N | V | H deriving Eq

main = do
  getLine
  s1 <- getLine
  s2 <- getLine
  print (domino N 1 s1 s2 `mod` (10^9+7))

domino _ acc "" "" = acc
domino N acc [_] [_] = acc*3
domino V acc [_] [_] = acc*2
domino H acc [_] [_] = acc
domino N acc (d1:e1:s1) (d2:e2:s2)
 | d1 == d2  = domino V (acc*3) (e1:s1) (e2:s2)
 | otherwise = domino H (acc*6) s1 s2
domino V acc (d1:e1:s1) (d2:e2:s2)
 | d1 == d2  = domino V (acc*2) (e1:s1) (e2:s2)
 | otherwise = domino H (acc*2) s1 s2
domino H acc (d1:e1:s1) (d2:e2:s2)
 | d1 == d2  = domino V acc (e1:s1) (e2:s2)
 | otherwise = domino H (acc*3) s1 s2