#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<cctype>
#include<string.h>
#include <stdlib.h>

#define PI 3.1415926
void swap(int* x, int* y) {
	int a = *x;
	int b = *y;
	*x = b;
	*y = a;
}
int factorial(int n);
int sum(int n, int*);
int ave(int n, int*);
int min(int n, int*), min(int n, int m);
int max(int n, int*), max(int n, int m);

int main() {
	int N;
	char r[2000];
	int f[10] = { 0 };
	f[1] = 1;
	int ff[10] = { 0 };
	r[0] = 'J';
	scanf("%d", &N);
	//printf("%d\n", N);
	for (int i = 1; i <= N; i++) {
		scanf(" %c", &r[i]);
	}
	//for (int i = 1; i <= N; i++) {
		//printf("%c", r[i]);
	//}
	//printf("\n");
	for (int i = 1; i <= N; i++) {
		if (r[i - 1] == 'J') {
			if (r[i] == 'J') {
				ff[1] = f[1] + f[3] + f[5] + f[7];
				ff[3] = f[1] + f[3] + f[5] + f[7];
				ff[5] = f[1] + f[3] + f[5] + f[7];
				ff[7] = f[1] + f[3] + f[5] + f[7];
			}
			else if (r[i] == 'O') {
				ff[2] = f[3] + f[7];
				ff[3] = f[1] + f[3] + f[5] + f[7];
				ff[6] = f[3] + f[5] + f[7];
				ff[7] = f[1] + f[3] + f[5] + f[7];
			}
			else if (r[i] == 'I') {
				ff[4] = f[5] + f[7];
				ff[5] = f[1] + f[3] + f[5] + f[7];
				ff[6] = f[3] + f[5] + f[7];
				ff[7] = f[1] + f[3] + f[5] + f[7];
			}
		}
		else if (r[i-1] == 'O') {
			if (r[i] == 'J') {
				ff[1] = f[3] + f[7];
				ff[3] = f[2] + f[3] + f[6] + f[7];
				ff[5] = f[3] + f[6] + f[7];
				ff[7] = f[2] + f[3] + f[6] + f[7];
			}
			else if (r[i] == 'O') {
				ff[2] = f[2] + f[3] + f[6] + f[7];
				ff[3] = f[2] + f[3] + f[6] + f[7];
				ff[6] = f[2] + f[3] + f[6] + f[7];
				ff[7] = f[2] + f[3] + f[6] + f[7];
			}
			else if (r[i] == 'I') {
				ff[4] = f[6] + f[7];
				ff[5] = f[3] + f[6] + f[7];
				ff[6] = f[2] + f[3] + f[6] + f[7];
				ff[7] = f[2] + f[3] + f[6] + f[7];
			}
		}
		else if (r[i - 1] == 'I') {
			if (r[i] == 'J') {
				ff[1] = f[5] + f[7];
				ff[3] = f[5] + f[6] + f[7];
				ff[5] = f[4] + f[5] + f[6] + f[7];
				ff[7] = f[4] + f[5] + f[6] + f[7];
			}
			else if (r[i] == 'O') {
				ff[2] = f[6] + f[7];
				ff[3] = f[5] + f[6] + f[7];
				ff[6] = f[4] + f[5] + f[6] + f[7];
				ff[7] = f[4] + f[5] + f[6] + f[7];
			}
			else if (r[i] == 'I') {
				ff[4] = f[4] + f[5] + f[6] + f[7];
				ff[5] = f[4] + f[5] + f[6] + f[7];
				ff[6] = f[4] + f[5] + f[6] + f[7];
				ff[7] = f[4] + f[5] + f[6] + f[7];
			}
		}
		for (int j = 1; j <= 7; j++) {
			//printf("%d ", ff[j]);
			f[j] = ff[j]%10007;
			ff[j] = 0;
		}
		//printf("\n");
	}
	printf("%d\n", sum(8,f)%10007);
	//printf("%c", r[1]);
	return 0;
}

int factorial(int n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}
int sum(int n, int *all) {
	int total = 0;
	for (int i = 0; i < n; ++i) {
		total += all[i];
	}
	return total;
}
int ave(int n, int *all) {
	int total = 0;
	for (int i = 0; i<n; ++i) {
		total += all[i];
	}
	return total / n;
}
int min(int n, int *all) {

	int min = all[0];
	for (int i = 1; i < n; ++i) {
		if (all[0] > all[i]) {
			min = all[i];
		}
	}
	return min;
}
int max(int n, int *all) {
	int max = all[0];
	for (int i = 1; i<n; ++i) {
		if (all[0]<all[i]) {
			max = all[i];
		}
	}
	return max;
}
int max(int n, int m) {
	if (n >= m) {
		return n;
	}
	else {
		return m;
	}
}
int min(int n, int m) {
	if (n >= m) {
		return m;
	}
	else {
		return n;
	}
}

Measured memory_bytes: 2712