#D2452. Bus

    ID: 2044 Type: Default 3000ms 268MiB

Bus

Bus

Problem

There are N N bus stops clockwise, numbered from 1 1 to N N in a circle. Adjacent bus stops are connected by a road. For each i (1 lei leN) i \ (1 \ le i \ le N) , the length of the direct connection between the bus stop i i and the bus stop i+1 i + 1 is di d_i meters. However, bus stop N+1 N + 1 means bus stop 1 1 .

There are M M buses. The j (1 lej leM) j \ (1 \ le j \ le M) th bus runs clockwise when cj=R c_j ='R' and counterclockwise when cj=L c_j ='L' . It also takes tj t_j seconds to depart bus stop bj b_j at time 0 0 and travel 1 1 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 Q Q times.

  • Find the minimum time required to depart bus stop xk x_k at time 0 0 and travel to bus stop yk y_k using only the bus.

Constraints

The input satisfies the following conditions.

  • 3 leqN leq105 3 \ leq N \ leq 10 ^ 5
  • 1 leqM leq105 1 \ leq M \ leq 10 ^ 5
  • 1 leqQ leq105 1 \ leq Q \ leq 10 ^ 5
  • 1 leqdi leq102 (1 leqi leqN) 1 \ leq d_i \ leq 10 ^ 2 \ (1 \ leq i \ leq N)
  • cj=R orLˊ (1 leqj leqM) c_j ='R' \ or \'L' \ (1 \ leq j \ leq M)
  • 1 leqbj leqN (1 leqj leqM) 1 \ leq b_j \ leq N \ (1 \ leq j \ leq M)
  • 1 leqtj leq105 (1 leqj leqM) 1 \ leq t_j \ leq 10 ^ 5 \ (1 \ leq j \ leq M)
  • 1 leqxk,yk leqN (1 leqk leqQ) 1 \ leq x_k, y_k \ leq N \ (1 \ leq k \ leq Q)
  • xk neqyk (1 leqk leqQ) x_k \ neq y_k \ (1 \ leq k \ leq Q)
  • All numbers given in the input are integers

Input

The input is given in the following format.

N N M M Q Q d1 d_1  ldots \ ldots dN d_N c1 c_1 b1 b_1 t1 t_1  vdots \ vdots cM c_M bM b_M tM t_M x1 x_1 y1 y_1  vdots \ vdots xQ x_Q yQ y_Q

The number of bus stops N N , the number of buses M M , and the number of queries Q Q 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 M M line starting from the third line, separated by blanks. Query information is given in the following Q Q line, separated by blanks.

Output

The output consists of Q Q lines. Output the minimum required time for each query. Print the answer to the k k th query on the k k 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.

  • 3 leqN leq105 3 \ leq N \ leq 10 ^ 5
  • 1 leqM leq105 1 \ leq M \ leq 10 ^ 5
  • 1 leqQ leq105 1 \ leq Q \ leq 10 ^ 5
  • 1 leqdi leq102 (1 leqi leqN) 1 \ leq d_i \ leq 10 ^ 2 \ (1 \ leq i \ leq N)
  • cj=R orLˊ (1 leqj leqM) c_j ='R' \ or \'L' \ (1 \ leq j \ leq M)
  • 1 leqbj leqN (1 leqj leqM) 1 \ leq b_j \ leq N \ (1 \ leq j \ leq M)
  • 1 leqtj leq105 (1 leqj leqM) 1 \ leq t_j \ leq 10 ^ 5 \ (1 \ leq j \ leq M)
  • 1 leqxk,yk leqN (1 leqk leqQ) 1 \ leq x_k, y_k \ leq N \ (1 \ leq k \ leq Q)
  • xk neqyk (1 leqk leqQ) x_k \ neq y_k \ (1 \ leq k \ leq Q)
  • All numbers given in the input are integers

Input

The input is given in the following format.

N N M M Q Q d1 d_1  ldots \ ldots dN d_N c1 c_1 b1 b_1 t1 t_1  vdots \ vdots cM c_M bM b_M tM t_M x1 x_1 y1 y_1  vdots \ vdots xQ x_Q yQ y_Q

The number of bus stops N N , the number of buses M M , and the number of queries Q Q 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 M M line starting from the third line, separated by blanks. Query information is given in the following Q Q line, separated by blanks.

outputFormat

Output

The output consists of Q Q lines. Output the minimum required time for each query. Print the answer to the k k th query on the k k 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>