You are given a functional graph with vertices: for every vertex there is exactly one directed edge from to p_i (1 \le p_i \le n). Additionally, on each edge (i \to p_i) a lowercase Latin letter c_i is written.
For a query (u, v, k) consider the unique directed walk that starts at and, at each step, follows the outgoing edge of the current vertex, stopping at the first visit of vertex . If the walk never visits , then is unreachable from .
If is unreachable from , the answer is .
Otherwise, let the sequence of edges on this walk be e_1, e_2, \dots, e_m in order. From these edges build a string as follows:
Start with the empty string .
For i = 1, 2, \dots, m: let be the letter written on edge e_i. Let be the length of the longest suffix of that consists only of (if the last character of is not , then \ell = 0). Append the character to exactly \ell + 1 times.
You must output the -th character of . If |S| < k, output .
The first line contains two integers and (1 \le n, q \le 2 \cdot 10^{5}).
Each of the next lines contains an integer p_i and a character c_i (1 \le p_i \le n), describing the edge (i \to p_i) and the letter written on it.
Each of the next lines contains a query with three values u, v, k (1 \le u, v \le n, 1 \le k \le 10^{12}).
For each query, print the -th character of the string constructed from the walk u \to v, or print if is unreachable from or if |S| < k.
Example 1
For the sample test case, the graph looks as follows:
For the first query, we have (u, v, k) = (8, 3, 8).
Walk (follow outgoing edges from until the first time we reach ): 8 \to 6 \to 1 \to 2 \to 3.
The letters along the edges on this walk are: b, a, a, a.
We build step by step. Before processing a letter , let be the length of the current trailing suffix of consisting only of ; then append exactly \ell + 1 times.
Step 1 (edge 8 \to 6, letter ): is empty, \ell= 0. Append once; b.
Step 2 (edge 6 \to 1, letter ): b, \ell= 0. Append once; ba.
Step 3 (edge 1 \to 2, letter ): ba, \ell= 1. Append twice; baaa.
Step 4 (edge 2 \to 3, letter ): baaa, \ell= 3. Append four times; baaaaaaa.
Thus baaaaaaa and |S| = 8. We have k = 8, and the 8th character of S = a so the answer is .
For the second query, we have (u, v, k) = (8, 3, 9). The walk is the same as in the first query, so baaaaaaa and |S| = 8. Since |S| < k, the -th character does not exist; the answer is .
For the third query, we have (u, v, k) = (9, 1, 1). is not reachable from so the answer is .
1. Subtask ( points): (n,q \le 1000)
2. Subtask ( points): (n \le 5000)
3. Subtask ( points): (c_i = c_j for all i,j \le n)
4. Subtask ( points): (Every vertex is reachable from any other vertex)
5. Subtask ( points): (n,q \le 50000)
6. Subtask ( points): Without additional constraints