Fragments

No attempts yetTime limit1sMemory limit128 MB

Problem

You are given a set AA of positive integers, described as a union of closed intervals. For a string of digits xx, determine how many times xx occurs as a fragment (a contiguous substring) inside the decimal representations of the numbers in AA. If xx occurs several times inside one number, every occurrence is counted, and occurrences are allowed to overlap.

Input

The first line contains two integers nn and mm (1n50001 \le n \le 5000, 1m5000001 \le m \le 500000): the number of intervals describing the set AA and the number of queries.

Each of the next nn lines contains two integers aia_i and bib_i. They satisfy 1a1b1<a2b2<a3b3<<anbn10181 \le a_1 \le b_1 < a_2 \le b_2 < a_3 \le b_3 < \dots < a_n \le b_n \le 10^{18} and describe the set A=[a1,b1][a2,b2][an,bn]A = [a_1, b_1] \cup [a_2, b_2] \cup \dots \cup [a_n, b_n], where each interval is inclusive on both ends.

Each of the next mm lines contains one query: a string of digits xjx_j with between 11 and 1919 digits, each digit from 00 to 99. A query string may start with the digit 00.

Output

Print mm lines. The jj-th line must contain a single integer: the total number of occurrences of xjx_j as a fragment across all numbers in the set AA, counting every occurrence separately, including repeated and overlapping occurrences inside the same number.