Frankenstein's Banner


The MAPS Academy team is preparing the captions for an Olympic archery stream. The full chant for the day is one long lowercase string SS, but the director keeps asking for short slices of it between ends, so the team has to assemble them from prepared banner strips.

The team has nn reusable banner templates, written as strings t1,t2,…,tnt_1, t_2, \ldots, t_n. There are infinitely many copies of every template, and using one copy has cost 11.

Before using a copy, the team may cut off any suffix, possibly the empty suffix. Equivalently, one copy may contribute any prefix of its template. The chosen prefixes may then be concatenated in any order.

For each request [li,ri)[l_i,r_i), determine the minimum number of template copies needed to form exactly the substring S[li,ri)S[l_i,r_i). The indices are zero-based, and the right endpoint is not included. If the substring cannot be formed, output -1.

Input

The first line contains two integers nn (1≤n≤1041 \leq n \leq 10^4) and mm (1≤m≤3×1051 \leq m \leq 3 \times 10^5): the number of banner templates and the number of requests.

The next nn lines contain the nonempty strings tit_i. All strings consist only of lowercase English letters. The total length of all strings tit_i is at most 5×1055 \times 10^5.

The next line contains the string SS, consisting only of lowercase English letters (1≤∣S∣≤3×1051 \leq |S| \leq 3 \times 10^5).

Each of the next mm lines contains two integers lil_i and rir_i (0≤li<ri≤∣S∣0 \leq l_i < r_i \leq |S|), describing one requested substring.

Output

Print mm lines. The ii-th line must contain the answer to query ii, or -1 if it is impossible.

Example 1

Input 1
3 8
aim
arrow
gold
aimarrowgoldaimx
0 3
3 6
0 8
0 15
8 15
1 3
15 16
0 16
Output 1
1
1
2
4
2
-1
-1
-1

Comments1


New comment


Log in to join the discussion.