/*
   ЗАПУСКАЕМ СТЕНУ ИЗ КРЕМА
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
   💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩💩
*/

#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

const int N = 60 + 1;
const int M = 1e9 + 7;

int dp[N][3][3];
char s[N][2];

inline int add(int a, int b)
{
    return (a + b) % M;
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> s[i][0];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> s[i][1];
    }
    if (s[0][0] == s[0][1])
    {
        for (int i = 0; i < 3; i++)
        {
            dp[1][i][i] = 1;
        }
    }
    else
    {
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (i == j)
                {
                    continue;
                }
                dp[1][i][j] = 1;
            }
        }
    }
    for (int i = 1; i < n; i++)
    {
        for (int w = 0; w < 3; w++)
        {
            for (int w1 = 0; w1 < 3; w1++)
            {
                for (int cur = 0; cur < 3; cur++)
                {
                    for (int c1 = 0; c1 < 3; c1++)
                    {
                        if (s[i][0] == s[i][1] && cur != c1)
                        {
                            continue;
                        }
                        if (s[i][0] != s[i][1] && cur == c1)
                        {
                            continue;
                        }
                        if (i != 0 && s[i - 1][0] != s[i][0] && cur == w)
                        {
                            continue;
                        }
                        if (i != 0 && s[i - 1][1] != s[i][1] && c1 == w1)
                        {
                            continue;
                        }
                        if (i != 0 && s[i - 1][0] == s[i][0] && cur != w)
                        {
                            continue;
                        }
                        if (i != 0 && s[i - 1][1] == s[i][1] && c1 != w1)
                        {
                            continue;
                        }
                        dp[i + 1][cur][c1] = add(dp[i + 1][cur][c1], dp[i][w][w1]);
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            ans = add(ans, dp[n][i][j]);
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256