#include <cstdio>

int N;
char S1[60], S2[60];
long long memo[55][55][3][3];
long long D = 1000000007;
long long res;

int lcolor(int c1, int c2)
{
	int i;
	int h[3];
	for(i=0; i<3; i++)
		h[i] = 0;
	h[c1] = 1;
	h[c2] = 1;
	for(i=0; i<3; i++){
		if(h[i] == 0)
			return i;
	}
}

void solve()
{
	int i, j, i2, j2, k;
	int c;
	if(S1[0] == S2[0]){
		for(i=0; i<3; i++){
			memo[0][0][i][i] = 1;
		}		
	}
	else{
		for(i=0; i<3; i++){
			for(j=0; j<3; j++){
				if(i != j){
					memo[1][1][i][j] = 1;
				}
			}
		}
	}
	for(i=0; i<N; i++){
		for(j=0; j<N; j++){
			for(i2=0; i2<3; i2++){
				for(j2=0; j2<3; j2++){
					if(memo[i][j][i2][j2] > 0){
						if(i==1 && j==3)
							int oo = 1;
						if(i==j){
							if(i+1<N){
								if(S1[i+1] == S2[j+1]){
									if(i2!=j2){
										c = lcolor(i2, j2);
										memo[i+1][j+1][c][c] += memo[i][j][i2][j2];
										memo[i+1][j+1][c][c] %= D;
									}
									else{
										for(k=0; k<3; k++){
											if(k!=i2){
												memo[i+1][j+1][k][k] += memo[i][j][i2][j2];
												memo[i+1][j+1][k][k] %= D;
											}
										}
									}
								}
								else{
									if(i+2<N){
										for(k=0; k<3; k++){
											if(k != i2){
												memo[i+2][j][k][j2] += memo[i][j][i2][j2];
												memo[i+2][j][k][j2] %= D;
											}
										}
									}
									if(j+2<N){
										for(k=0; k<3; k++){
											if(k != j2){
												memo[i][j+2][i2][k] += memo[i][j][i2][j2];
												memo[i][j+2][i2][k] %= D;
											}
										}
									}
								}
							}
						}
						else{
							if(i+2<N && i<j){
								if(i+1==j){
									if(S1[i+1] == S1[i+2]){
										c = lcolor(i2, j2);
										memo[i+2][j][c][j2] += memo[i][j][i2][j2];
										memo[i+2][j][c][j2] %= D;
									}
								}
								else if(i+2==j){
									if(i2==j2){
										if(S1[i+1] == S1[i+2]){
											for(k=0; k<3; k++){
												if(k != i2){
													memo[i+2][j][k][j2] += memo[i][j][i2][j2];
													memo[i+2][j][k][j2] %= D;
												}
											}
										}
									}
									else{
										if(S1[i+1] == S1[i+2]){
											c = lcolor(i2, j2);
											memo[i+2][j][c][j2] += memo[i][j][i2][j2];
											memo[i+2][j][c][j2] %= D;
										}
									}
								}
							}
							if(j+2<N && j<i){
								if(j+1==i){
									if(S2[j+1] == S2[j+2]){
										c = lcolor(i2, j2);
										memo[i][j+2][i2][c] += memo[i][j][i2][j2];
										memo[i][j+2][i2][c] %= D;
									}
								}
								/*else if(j+2==i){
									if(i2==j2){
										if(S2[j+1] == S2[j+2]){
											for(k=0; k<3; k++){
												if(k != i2){
													memo[i][j+2][k][j2] += memo[i][j][i2][j2];
													memo[i][j+2][k][j2] %= D;
												}
											}
										}
									}
									else{
										if(S2[j+1] == S2[j+2]){
											c = lcolor(i2, j2);
											memo[i][j+2][i2][c] += memo[i][j][i2][j2];
											memo[i][j+2][i2][c] %= D;
										}
									}
								}*/
							}
						}
					}
				}
			}
		}
	}
	res = 0;
	for(i=0; i<3; i++){
		for(j=0; j<3; j++){
			res += memo[N-1][N-1][i][j];
			res %= D;
		}
	}
	printf("%lld\n", res);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	scanf("%d", &N);
	scanf("%s", &S1);
	scanf("%s", &S2);
	solve();
	return 0;
}

Measured memory_bytes: 256