Card Trick

No attempts yetTime limit2sMemory limit128 MB

Problem

I am learning card tricks to impress my girlfriend Alice. My latest trick is a probabilistic one, so it works in most cases but not in every case.

To perform the trick I first shuffle many playing cards and lay them out in one line, faces up, on the table. There are at least ten cards on the table. Alice secretly selects one of the first ten cards, that is, she chooses a secret number x0x_0 between 1 and 10 inclusive. From there she skips cards repeatedly. After selecting the card at position xix_i, whose face shows the value c(xi)c(x_i), she selects the card at position xi+1=xi+c(xi)x_{i+1} = x_i + c(x_i). J, Q, K count as 10 and A counts as 11.

Alice stops as soon as there is no card at position xi+c(xi)x_i + c(x_i).

I then run the same procedure from a randomly selected starting position, which may differ from the position Alice selected. It turns out that I often end up on the same card she does. Alice is very impressed by the trick.

The math behind it interests me more. Given my randomly selected starting position and the faces of every card I selected, including my final one, compute the probability that Alice chose a starting position that ends on the same final card. Assume her starting position is chosen with uniform probability between 1 and 10 inclusive.

I forgot to note the cards I skipped, so those cards are unknown. Assume the face of every unknown card is independent of the other faces and uniform over the possible faces (2 to 10, J, Q, K, A).

The number of unknown cards behind my final selected card is smaller than the value of that card. If my final card is a Q, then 0 to 9 unknown cards follow it.

Input

The input holds several test cases and continues to the end of the file. Each test case is given as follows.

  • One line with two integers nn and mm (1n1001 \le n \le 100, 1m101 \le m \le 10), where nn is the number of cards I selected and mm is the position of my first selected card, counted from 1.
  • One line with nn tokens that give the faces of the nn selected cards in the order I selected them, including the final card. Each face is either an integer vv (2v102 \le v \le 10) or one of the characters J, Q, K, A.

Output

For each test case, print on one line the probability that Alice chooses a starting position leading to the same final card.

The probability is a rational number p/qp/q. Under the constraints above qq is never a multiple of 10000000071\,000\,000\,007, so exactly one integer rr with 0r<10000000070 \le r < 1\,000\,000\,007 satisfies r×qp(mod1000000007)r \times q \equiv p \pmod{1\,000\,000\,007}. Print that rr. For a probability of exactly 1/101/10, print 700000005700000005.