local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
----
local MOD = 1000000007
local N = read.nl()
local s1 = read.l():totable()
local s2 = read.l():totable()

local H = 'H'
local V = 'V'

local function iter()
    local x = 1
    local y = 1
    local function start()
        while true do
            if x > N then
                return
            end
            if y == 1 then
                local a, b = s1[x], s1[x+1]
                if a == b then
                    coroutine.yield(H)
                    y = 2
                else
                    coroutine.yield(V)
                    x = x + 1
                end
            else
                coroutine.yield(H)
                y = 1
                x = x + 2
            end
        end
    end
    return coroutine.wrap(start)
end

local ans = 1
local state = 0
--[[
    state 0: Initial state
    state 1: First domino is H
    state 2: A V is on the left, now y = 1
    state 3: Two Hs are on the left, now y = 1
    state 4: A V is on the left, now y = 2
    state 5: Two Hs are on the left, now y = 2 (calculated at state 3.)
]]
for b in iter() do
    if state == 0 then
        if b == H then
            state = 1
        else
            state = 2
        end
        ans = ans * 3
    elseif state == 1 then
        assert(b == H)
        ans = ans * 2
        state = 3
    elseif state == 2 then
        if b == H then
            state = 4
        else
            state = 2
        end
        ans = ans * 2
    elseif state == 3 then
        if b == H then
            ans = ans * 3
            state = 5
        else
            ans = ans * 1
            state = 2
        end
    elseif state == 4 then
        ans = ans * 1
        state = 3
    elseif state == 5 then
        state = 3
    end
    ans = ans % MOD
end

print(ans)
