#D11410. RMQ 2

    ID: 9492 Type: Default 2000ms 268MiB

RMQ 2

RMQ 2

Problem

Given two sequences of length N N , A A and B B . First, the i i item in the sequence A A is ai a_i , and the i i item in the sequence B B is bi b_i .

Since a total of Q Q of statements of the following format are given, create a program that processes in the given order.

Each statement is represented by three integers x,y,z x, y, z .

  • Set the value of the y y item in the sequence A A to z z . (When x=1 x = 1 )
  • Set the value of the y y item in the sequence B B to z z . (When x=2 x = 2 )
  • Find and report the smallest value in the z z item from the y y item in the sequence A A . (When x=3 x = 3 )
  • Find and report the smallest value in the z z item from the y y item in the sequence B B . (When x=4 x = 4 )
  • Change the sequence A A to be exactly the same as the sequence B B . (When x=5 x = 5 )
  • Change the sequence B B to be exactly the same as the sequence A A . (When x=6 x = 6 )

Constraints

The input satisfies the following conditions.

  • 2 leN le2 times105 2 \ le N \ le 2 \ times 10 ^ 5
  • 2 leQ le2 times105 2 \ le Q \ le 2 \ times 10 ^ 5
  • 1 leai le109 1 \ le a_i \ le 10 ^ 9
  • 1 lebi le109 1 \ le b_i \ le 10 ^ 9
  • 1 lexi le6 1 \ le x_i \ le 6
  • 1 leyi leN 1 \ le y_i \ le N (when 1 lexi le4 1 \ le x_i \ le 4 )
  • yi=1 y_i = -1 (when xi=5,6 x_i = 5, 6 )
  • 1 lezi le109 1 \ le z_i \ le 10 ^ 9 (when xi=1,2 x_i = 1, 2 )
  • yi lezi leN y_i \ le z_i \ le N (when xi=3,4 x_i = 3, 4 )
  • zi=1 z_i = -1 (when xi=5,6 x_i = 5, 6 )
  • All inputs are integers

Input

The input is given in the following format.

N N a1 a_ {1} a2 a_ {2} ... aN a_ {N} b1 b_ {1} b2 b_ {2} ... bN b_ {N} Q Q x1 x_1 y1 y_1 z1 z_1 x2 x_2 y2 y_2 z2 z_2 ... xQ x_Q yQ y_Q zQ z_Q

Output

Every time a statement of x=3 x = 3 or x=4 x = 4 is given by input, the found value is output on one line.

Example

Input

5 1 3 5 7 9 6 2 3 2 6 10 1 3 4 3 4 5 4 2 3 5 -1 -1 2 3 8 3 2 5 4 3 3 1 1 1 6 -1 -1 3 1 5

Output

7 2 2 8 1

inputFormat

input satisfies the following conditions.

  • 2 leN le2 times105 2 \ le N \ le 2 \ times 10 ^ 5
  • 2 leQ le2 times105 2 \ le Q \ le 2 \ times 10 ^ 5
  • 1 leai le109 1 \ le a_i \ le 10 ^ 9
  • 1 lebi le109 1 \ le b_i \ le 10 ^ 9
  • 1 lexi le6 1 \ le x_i \ le 6
  • 1 leyi leN 1 \ le y_i \ le N (when 1 lexi le4 1 \ le x_i \ le 4 )
  • yi=1 y_i = -1 (when xi=5,6 x_i = 5, 6 )
  • 1 lezi le109 1 \ le z_i \ le 10 ^ 9 (when xi=1,2 x_i = 1, 2 )
  • yi lezi leN y_i \ le z_i \ le N (when xi=3,4 x_i = 3, 4 )
  • zi=1 z_i = -1 (when xi=5,6 x_i = 5, 6 )
  • All inputs are integers

Input

The input is given in the following format.

N N a1 a_ {1} a2 a_ {2} ... aN a_ {N} b1 b_ {1} b2 b_ {2} ... bN b_ {N} Q Q x1 x_1 y1 y_1 z1 z_1 x2 x_2 y2 y_2 z2 z_2 ... xQ x_Q yQ y_Q zQ z_Q

outputFormat

Output

Every time a statement of x=3 x = 3 or x=4 x = 4 is given by input, the found value is output on one line.

Example

Input

5 1 3 5 7 9 6 2 3 2 6 10 1 3 4 3 4 5 4 2 3 5 -1 -1 2 3 8 3 2 5 4 3 3 1 1 1 6 -1 -1 3 1 5

Output

7 2 2 8 1

样例

5
1 3 5 7 9
6 2 3 2 6
10
1 3 4
3 4 5
4 2 3
5 -1 -1
2 3 8
3 2 5
4 3 3
1 1 1
6 -1 -1
3 1 5
7

2 2 8 1

</p>