
import std.stdio;
import std.conv;
import std.array;
import std.math;
import std.string;

int N;
string S;
int mem[1000][100];

void main()
{
  N = to!int(chomp(readln()));
  S = readln();
  writeln(dp(0b00000100, 0));
}

int dp(int n, int m)
{
  if(m == N)
    return 1;
  if(mem[n][m])
    return mem[n][m];
  int ans = 0;
  for(auto i = 0; i < 0b00001000; i++)
  {
    switch(S[m])
    {
      case 'J':
        if((i & 0b00000100) == 0)
          continue;
        break;
      case 'O':
        if((i & 0b00000010) == 0)
          continue;
        break;
      case 'I':
        if((i & 0b00000001) == 0)
          continue;
        break;
      default:
    }
    if((i & n) == 0)
      continue;
    ans += dp(i, m + 1);
  }
  return mem[n][m] = ans % 10007;
}