import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

private val MOD = 1000000007L

fun solve() {
    val n = inf.readLine()!!.toInt()
    val a = inf.readLine()!!.zip(inf.readLine()!!).map { arrayOf(it.first, it.second) }.toTypedArray()
    val dp = Array(n) { Array(3) { LongArray(3) } }
    for (i in 0..2) {
        for (j in 0..2) {
            if ((i == j) == (a[0][0] == a[0][1])) dp[0][i][j] = 1L
        }
    }
    for (i in 1 until n) {
        for (j in 0..2) {
            for (j1 in 0..2) if ((j == j1) == (a[i][0] == a[i - 1][0])) {
                for (k in 0..2) if ((j == k) == (a[i][0] == a[i][1])) {
                    for (k1 in 0..2) if ((k == k1) == (a[i][1] == a[i - 1][1])) {
                        dp[i][j][k] = (dp[i][j][k] + dp[i - 1][j1][k1]) % MOD
                    }
                }
            }
        }
    }
    println(dp[n - 1].fold(0L) { q, w -> (q + w.sum()) % MOD })
}

fun main(args: Array<String>) {
    solve()
    ouf.close()
}

val inf = BufferedReader(InputStreamReader(System.`in`))
val ouf = PrintWriter(System.out)