#abc271b. [abc271_b]Maintain Multiple Sequences

[abc271_b]Maintain Multiple Sequences

Problem Statement

There are NN sequences of integers.
The ii-th (1leqileqN)(1 \\leq i \\leq N) sequence has LiL_i terms; the jj-th (1leqjleqLi)(1 \\leq j \\leq L_i) term of the ii-th sequence is ai,ja_{i, j}.

You are given QQ queries. For the kk-th (1leqkleqQ)(1 \\leq k \\leq Q) query, given integers sks_k and tkt_k, find the tkt_k-th term of the sks_k-th sequence.

Constraints

  • 1leqN,Qleq2times1051 \\leq N, Q \\leq 2 \\times 10^5
  • Ligeq1,(1leqileqN)L_i \\geq 1 \\, (1 \\leq i \\leq N)
  • sumi=1NLileq2times105\\sum_{i=1}^N L_i \\leq 2 \\times 10^5
  • $1 \\leq a_{i, j} \\leq 10^9 \\, (1 \\leq i \\leq N, 1 \\leq j \\leq L_i)$
  • $1 \\leq s_k \\leq N, 1 \\leq t_k \\leq L_{s_k} \\, (1 \\leq k \\leq Q)$
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN QQ L1L_1 a1,1a_{1, 1} ldots\\ldots a1,L1a_{1, L_1} vdots\\vdots LNL_N aN,1a_{N, 1} ldots\\ldots aN,LNa_{N, L_N} s1s_1 t1t_1 vdots\\vdots sQs_Q tQt_Q

Output

Print QQ lines. The kk-th (1leqkleqQ)(1 \\leq k \\leq Q) line should contain the answer to the kk-th query.


Sample Input 1

2 2
3 1 4 7
2 5 9
1 3
2 1

Sample Output 1

7
5

The 11-st sequence is (1,4,7)(1, 4, 7) and the 22-nd is (5,9)(5, 9).
The answer to each query is as follows:

  • The 33-rd term of the 11-st sequence is 77.
  • The 11-st term of the 22-nd sequence is 55.

Sample Input 2

3 4
4 128 741 239 901
2 1 1
3 314 159 26535
1 1
2 2
3 3
1 4

Sample Output 2

128
1
26535
901