#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};

#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j);i++)
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define MOD 10007

typedef long long ll;
typedef pair < int , int > Pii;
int n;
string str;
int memo[1001][10];
int solve(int dep,int bef){
    if(dep == n){
        return 1;
    }
    if(memo[dep][bef] > 0)return memo[dep][bef];
    string S="";
    S=str[dep];
    int x = 0;
    if(S == "J")x = 0;
    if(S == "O")x = 1;
    if(S == "I")x = 2;
    if(bef == 6){/*JOI*/
        if(x == 0){
            memo[dep][bef] = solve(dep+1,0)+solve(dep+1,4)+solve(dep+1,3)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
        if(x == 1){
            memo[dep][bef] = solve(dep+1,1)+solve(dep+1,3)+solve(dep+1,5)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
        if(x == 2){
            memo[dep][bef] = solve(dep+1,2)+solve(dep+1,4)+solve(dep+1,5)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
    }
    
    else if(bef == 3){/*JO*/
        if(x == 0){
            memo[dep][bef] = solve(dep+1,0)+solve(dep+1,4)+solve(dep+1,3)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
        if(x == 1){
            memo[dep][bef] = solve(dep+1,1)+solve(dep+1,3)+solve(dep+1,5)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
        if(x == 2){
            memo[dep][bef] = solve(dep+1,5)+solve(dep+1,4)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
    }
    
    else if(bef == 4){/*JI*/
        if(x == 0){
            memo[dep][bef] = solve(dep+1,0)+solve(dep+1,4)+solve(dep+1,3)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
        if(x == 1){
            memo[dep][bef] = solve(dep+1,3)+solve(dep+1,5)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
        if(x == 2){
            memo[dep][bef] = solve(dep+1,2)+solve(dep+1,4)+solve(dep+1,5)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
    }
    
    else if(bef == 5){/*OI*/
        if(x == 0){
            memo[dep][bef] = solve(dep+1,4)+solve(dep+1,3)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
        if(x == 1){
            memo[dep][bef] = solve(dep+1,1)+solve(dep+1,3)+solve(dep+1,5)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
        if(x == 2){
            memo[dep][bef] = solve(dep+1,2)+solve(dep+1,4)+solve(dep+1,5)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
    }
    
    else if(bef == 0){/*J*/
        if(x == 0){
            memo[dep][bef] = solve(dep+1,0)+solve(dep+1,3)+solve(dep+1,4)+ solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
        if(x == 1){
            memo[dep][bef] = solve(dep+1,3)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
        if(x == 2){
            memo[dep][bef] = solve(dep+1,4)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
    }
    
    else if(bef == 1){/*O*/
        if(x == 0){
            memo[dep][bef] = solve(dep+1,3)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
        if(x == 1){
            memo[dep][bef] = solve(dep+1,1)+solve(dep+1,3)+solve(dep+1,5)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
        if(x == 2){
            memo[dep][bef] = solve(dep+1,5)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
    }
    
    else if(bef == 2){/*I*/
        if(x == 0){
            memo[dep][bef] = solve(dep+1,4)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
        if(x == 1){
            memo[dep][bef] = solve(dep+1,5)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
        if(x == 2){
            memo[dep][bef] = solve(dep+1,2)+solve(dep+1,4)+solve(dep+1,5)+solve(dep+1,6);memo[dep][bef]%=MOD; return memo[dep][bef];
        }
    }
}
int main(){
    int ans = 0;
    scanf("%d",&n);
    string sub;
    cin >> sub;
    str=sub;
    ans = solve(0,0);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1408