let m = 1000000007
let ( *^ ) x y = x * y mod m

let () = Scanf.scanf "%d\n%s\n%s\n" @@ fun n s1 s2 ->
  Array.init (n - 1) (( + ) 1)
  |> Array.fold_left (fun acc i ->
      if s1.[i] = s2.[i] then
        if s1.[i - 1] = s2.[i - 1] then 2 *^ acc
        else acc
      else
        if s1.[i - 1] = s1.[i] then acc
        else if s1.[i - 1] = s2.[i - 1] then 2 *^ acc
        else 3 *^ acc) (if s1.[0] = s2.[0] then 3 else 6)
  |> Printf.printf "%d\n"