Chiaki has a B-based digital string s of length n. She has prepared m queries for the string.
In the i-th query, she would like to know the number of substring s_l..r (1≤l≤r≤n) of s such that after changing at most one digit in s_l..r to some digit in the set A_i, the digital root of s_l..r equals to x_i.
We should remind you that a digital root d(x) of the B-based digital string x (x may have some leading zeros) is the sum s(x) of all the digits of this number, if s(x)≤B−1, otherwise it is d(s(x)). For example, a digital root of the number 6543_10 is calculated as follows: d(6543_10)=d(6_10+5_10+4_10+3_10)=d(18_10)=9_10, d(abcd_16)=d(2e_16)=d(10_16)=1_16.
Note that in this problem we will use the lowercase English letters from 'a' to 'f' to represent the digits with values from 10 to 15.
The first line contains three integers n, m and B (1≤n,m≤220,2≤B≤16) -- the length of the string, the number of queries and the base of the number.
The second line contains a B-based digital string s of length n.
Each of the following m lines contains a character x_i and a B-based string a_i (1≤∣a_i∣≤B)-- the expected value of digital root and the set A_i. All characters in a_i are distinct.
For each query, output an integer denoting the number of substrings.