### constant

MOD = 10007
IDS = {"J" => 0, "O" => 1, "I" => 2}

### main

n = gets.strip.to_i
sched = gets.strip

counts = 8.times.map{0}
counts[1] = 1

for i in (0...n)
  pcounts = counts
  counts = [0]

  rbit = 1 << IDS[sched[i]]

  for cmem in (1..7)
    cnt = 0
    if (cmem & rbit) != 0
      for pmem in (1..7)
        if (cmem & pmem) != 0
          cnt = (cnt + pcounts[pmem]) % MOD
        end
      end
    end
    counts[cmem] = cnt
  end
end

sum = counts.inject(0){|s, c| (s + c) % MOD}
puts sum