#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}


void func(void)
{
//DEBUG_OUT("----\n");
#define MOD		(1000000000 + 7)	// 10^9 + 7
#define T(n)	((n) % (MOD))		// mod 10^9 + 7
    uint32 N;
    string s1, s2;
    cin >> N;
    cin >> s1;
    cin >> s2;

    if(N==1){
        cout << 3 << endl;
        return;
    }
    const uint8 TYPE_HH = 0;
    const uint8 TYPE_VV = 1;
    const uint8 TYPE_V = 2;
    vector<uint8> typeList;
    for(uint32 i=0; i<N-1; i++){
        // TYPE_HH
        if(s1[i] == s1[i+1]){
            typeList.push_back(TYPE_HH);
            i++;
        }
        // TYPE_V
        if(s1[i]==s2[i]){
            typeList.push_back(TYPE_V);
        }
    }
    if(s1[N-1]==s2[N-1]){
        typeList.push_back(TYPE_V);
    }

    for(uint32 i=0; i<typeList.size(); i++){
        if(typeList[i]==TYPE_V){ DEBUG_OUT("v"); }
        else if(typeList[i]==TYPE_VV){ DEBUG_OUT("W"); }
        else{ DEBUG_OUT("H"); }
    }
    DEBUG_OUT("\n-----\n");

    vector<uint8> typeList2;
    for(uint32 i=0; i<typeList.size()-1; i++){
        if(typeList[i] == TYPE_HH){
            typeList2.push_back(TYPE_HH);
        }else if(typeList[i]==TYPE_V && typeList[i+1]==TYPE_V){
            typeList2.push_back(TYPE_VV);
            i++;
        }else{
            typeList2.push_back(TYPE_V);
        }
    }

    for(uint32 i=0; i<typeList2.size(); i++){
        if(typeList2[i]==TYPE_V){ DEBUG_OUT("v"); }
        else if(typeList2[i]==TYPE_VV){ DEBUG_OUT("W"); }
        else{ DEBUG_OUT("H"); }
    }
    DEBUG_OUT("\n-----\n");

    uint32 ans;
    uint8 prevType;

        // first type
    if(typeList[0] == TYPE_V){
        ans = 3;
        prevType = TYPE_V;
    }else{ // TYPE_HH
        ans = 6;
        prevType = TYPE_HH;
    }
    //
    for(uint32 i=1; i<typeList.size(); i++){
        uint8 type = typeList[i];
        if(prevType == TYPE_V){
            if(type == TYPE_V){
                ans = T(ans * 2);
            }else{ // TYPE_HH
                ans = T(ans * 2);
            }
        }else{ // TYPE_HH
            if(type == TYPE_V){
                ans = T(ans * 1);
            }else{ // TYPE_HH
                ans = T(ans * 3);
            }
        }
        prevType = type;
    }

#if 0
    // first type
    if(typeList2[0] == TYPE_V){
        ans = 3;
        prevType = TYPE_V;
    }else if(typeList2[0] == TYPE_VV){
        ans = 6;
        prevType = TYPE_VV;
    }else{
        ans = 6;
        prevType = TYPE_HH;
    }
    //
    for(uint32 i=1; i<typeList2.size(); i++){
        uint8 type = typeList2[i];
        if(prevType == TYPE_V){
            if(type == TYPE_VV){
                ans = T(ans * 4);
            }else{ // TYPE_HH
                ans = T(ans * 2);
            }
        }else if(prevType == TYPE_VV){
            if(type == TYPE_VV){
                ans = T(ans * 4);
            }else if(type == TYPE_HH){
                ans = T(ans * 2);
            }else{ // TYPE_V
                ans = T(ans * 2);
            }
        }else{ // TYPE_HH
            if(type == TYPE_VV){
                ans = T(ans * 2);
            }else if(type == TYPE_HH){
                ans = T(ans * 3);
            }else{ // TYPE_V
                ans = T(ans * 1);
            }
        }
    }
#endif
    cout << ans << endl;

    return;
}



Measured memory_bytes: 256