There're $$$n$$$ robots placed on a number line. Initially, $$$i$$$-th of them occupies unit segment $$$[x_i, x_i + 1]$$$. Each robot has a program, consisting of $$$k$$$ instructions numbered from $$$1$$$ to $$$k$$$. The robot performs instructions in a cycle. Each instruction is described by an integer number. Let's denote the number corresponding to the $$$j$$$-th instruction of the $$$i$$$-th robot as $$$f_{i, j}$$$.
Initial placement of robots corresponds to the moment of time $$$0$$$. During one second from moment of time $$$t$$$ ($$$0 \le t$$$) until $$$t + 1$$$ the following process occurs:
An illustration of the process happening during one second:
Rectangles represent robots. Numbers inside rectangles correspond to instructions of robots. The final division into groups is marked with arcs. Below are the positions of the robots after moving. Only the left of the two rightmost groups moved. That's because these two groups tried to move towards each other, and were separated by exactly one unit segment.
Look at the examples for a better understanding of the process.
You need to answer several questions. What is the position of $$$a_i$$$-th robot at the moment of time $$$t_i$$$?
The first line contains two integer numbers $$$n$$$ and $$$k$$$ — the number of robots and the number of instructions in the program of one robot ($$$1 \le n \le 100$$$, $$$1 \le k \le 50$$$).
The next line contains $$$n$$$ integer numbers $$$x_i$$$ — positions of robots at moment of time $$$0$$$ ($$$-10^9 \le x_1 < x_2 < \dots < x_n < 10^9$$$).
The next $$$n$$$ lines contain descriptions of robots' programs. The $$$i$$$-th of these lines contains $$$k$$$ integer numbers $$$f_{i, j}$$$ ($$$|f_{i, j}| \le 10^6$$$).
The next line contains a single integer number $$$q$$$ — the number of questions you to answer ($$$1 \le q \le 1000$$$).
The next $$$q$$$ lines contain two integer number $$$a_i$$$ and $$$t_i$$$ each, meaning that you should find a position of $$$a_i$$$-th robot at moment of time $$$t_i$$$ ($$$1 \le a_i \le n$$$, $$$0 \le t_i \le 10^{18}$$$).
For every question output a single integer on the new line. Coordinate of the left border of unit segment occupied by the $$$a_i$$$-th robot at the moment of time $$$t_i$$$.
2 1 0 4 1 -1 8 1 0 2 0 1 1 2 1 1 2 2 2 1 3 2 3
0 4 1 3 1 2 1 2
2 1 0 4 2 -1 8 1 0 2 0 1 1 2 1 1 2 2 2 1 3 2 3
0 4 1 3 2 3 3 4
2 2 0 1 1 -1 -1 1 4 1 0 1 1 1 2 1 3
0 0 -1 0
1 3 0 3 -2 1 3 1 5 1 10 1 15
1 4 5
4 3 -8 -4 2 5 -1 3 0 1 -3 -4 2 -5 2 -1 -4 2 5 3 12 4 18 4 11 1 6 1 10
6 9 6 -8 -9
Name |
---|