#D2452. Bus
Bus
Bus
Problem
There are bus stops clockwise, numbered from to in a circle. Adjacent bus stops are connected by a road. For each , the length of the direct connection between the bus stop and the bus stop is meters. However, bus stop means bus stop .
There are buses. The th bus runs clockwise when and counterclockwise when . It also takes seconds to depart bus stop at time and travel meters.
In this matter
- The bus keeps running forever
- It doesn't take long to get on and off the bus
- At a bus stop, you can get on and off the bus the moment it passes the bus stop.
- You cannot get on and off the bus except at the bus stop
- You can take as many buses as you like
And.
Process the following query a total of times.
- Find the minimum time required to depart bus stop at time and travel to bus stop using only the bus.
Constraints
The input satisfies the following conditions.
- All numbers given in the input are integers
Input
The input is given in the following format.
The number of bus stops , the number of buses , and the number of queries are given on the first line, separated by blanks. Information on the road connecting the adjacent bus stops is given on the second line, separated by blanks. Bus information is given on the line starting from the third line, separated by blanks. Query information is given in the following line, separated by blanks.
Output
The output consists of lines. Output the minimum required time for each query. Print the answer to the th query on the line.
Examples
Input
3 1 6 1 2 3 R 1 1 1 2 1 3 2 1 2 3 3 1 3 2
Output
1 3 6 3 6 7
Input
4 6 7 45 72 81 47 R 1 47202 L 1 2156 L 2 95728 R 1 30739 L 3 39679 L 4 86568 3 2 3 4 1 2 2 4 4 3 1 4 2 1
Output
431200 629552 431200 629552 275968 101332 528220
inputFormat
input satisfies the following conditions.
- All numbers given in the input are integers
Input
The input is given in the following format.
The number of bus stops , the number of buses , and the number of queries are given on the first line, separated by blanks. Information on the road connecting the adjacent bus stops is given on the second line, separated by blanks. Bus information is given on the line starting from the third line, separated by blanks. Query information is given in the following line, separated by blanks.
outputFormat
Output
The output consists of lines. Output the minimum required time for each query. Print the answer to the th query on the line.
Examples
Input
3 1 6 1 2 3 R 1 1 1 2 1 3 2 1 2 3 3 1 3 2
Output
1 3 6 3 6 7
Input
4 6 7 45 72 81 47 R 1 47202 L 1 2156 L 2 95728 R 1 30739 L 3 39679 L 4 86568 3 2 3 4 1 2 2 4 4 3 1 4 2 1
Output
431200 629552 431200 629552 275968 101332 528220
样例
4 6 7
45 72 81 47
R 1 47202
L 1 2156
L 2 95728
R 1 30739
L 3 39679
L 4 86568
3 2
3 4
1 2
2 4
4 3
1 4
2 1
431200
629552
431200
629552
275968
101332
528220
</p>