C. Common Decoding

Time limit: 0.5sMemory limit: 256MBInput: Output:

A string of digits is called kk-decodable if there is exactly one way to split it into non-empty contiguous parts such that each part is the decimal representation of an integer between 11 and kk, inclusive. Leading zeros are not allowed, so a part may not start with the digit 0\texttt{0}.

For example, the string 1021\texttt{1021} is 2020-decodable: the only valid split is 10 ∣ 2 ∣ 1\texttt{10}\,|\,\texttt{2}\,|\,\texttt{1}. It is not 102102-decodable, because both 102 ∣ 1\texttt{102}\,|\,\texttt{1} and 10 ∣ 21\texttt{10}\,|\,\texttt{21} are valid.

You are given a string ss of length nn consisting of digits, and qq queries. Each query consists of two integers aa and bb. For each query, count the contiguous substrings of ss that are (a⋅10b)(a \cdot 10^b)-decodable.

Input

The first line contains two integers nn and qq (1≤n≤2×1051 \le n \le 2 \times 10^5, 1≤q≤2×1051 \le q \le 2 \times 10^5), the length of the string and the number of queries.

The second line contains the string ss of length nn, consisting of digits 0\texttt{0}--9\texttt{9}.

Each of the next qq lines contains two integers aa and bb (1≤a≤91 \le a \le 9, 0≤b<n0 \le b < n), describing a query.

Output

For each query, print a single integer: the number of contiguous substrings of ss that are (a⋅10b)(a \cdot 10^b)-decodable.

Example

stdin

6 2
102130
5 0
2 1

stdout

7
8

Note

In the first query, k=5⋅100=5k = 5 \cdot 10^0 = 5, so every part must be one of 1,2,3,4,51, 2, 3, 4, 5. Since no part can contain a 0\texttt{0}, a substring that contains a 0\texttt{0} has no valid split at all. The 77 substrings that are 55-decodable are:

  • s[1..1]=1s[1..1] = \texttt{1}, split as 1\texttt{1};
  • s[3..3]=2s[3..3] = \texttt{2}, split as 2\texttt{2};
  • s[3..4]=21s[3..4] = \texttt{21}, split as 2 ∣ 1\texttt{2}\,|\,\texttt{1};
  • s[3..5]=213s[3..5] = \texttt{213}, split as 2 ∣ 1 ∣ 3\texttt{2}\,|\,\texttt{1}\,|\,\texttt{3};
  • s[4..4]=1s[4..4] = \texttt{1}, split as 1\texttt{1};
  • s[4..5]=13s[4..5] = \texttt{13}, split as 1 ∣ 3\texttt{1}\,|\,\texttt{3};
  • s[5..5]=3s[5..5] = \texttt{3}, split as 3\texttt{3}.

In the second query, the 88 substrings that are 2020-decodable are 1\texttt{1}, 10\texttt{10}, 102\texttt{102}, 1021\texttt{1021}, 2\texttt{2}, 21\texttt{21}, 1\texttt{1} and 3\texttt{3}.

Log In or Sign Up to be able to send submissions!