#P7781. Dynamic Convex Hull

Dynamic Convex Hull

Dynamic Convex Hull

Problem Description

Let's first see a related classical algorithm to help you solve this problem: You will be given nn functions f1(x),f2(x),,fn(x)f_1(x),f_2(x),\dots,f_n(x), where fi(x)=aix+bif_i(x)=a_ix+b_i. When you want to find the minimum value of fi(x)f_i(x) for a fixed parameter xx, you just need to find the corresponding function on the convex hull. Now you will be given nn functions f1(x),f2(x),,fn(x)f_1(x),f_2(x),\dots,f_n(x), where fi(x)=(xai)4+bif_i(x)=(x-a_i)^4+b_i. You need to perform the following operations for mm times: · "1 a b\texttt{1 a b}" (1a50000,1b10181\leq a\leq 50\,000,1\leq b\leq 10^{18}): Add a new function fn+1(x)=(xa)4+bf_{n+1}(x)=(x-a)^4+b and then change nn into n+1n+1. · "2 t\texttt{2 t}" (1tn1\leq t\leq n): Delete the function ft(x)f_{t}(x). It is guaranteed that each function won't be deleted more than once. · "3 x\texttt{3 x}" (1x500001\leq x\leq 50\,000): Query for the minimum value of fi(x)f_i(x), where 1in1\leq i\leq n and the function fi(x)f_i(x) has not been deleted yet.

Input

The first line of the input contains a single integer TT (1T51 \leq T \leq 5), the number of test cases. For each case, the first line of the input contains two integers nn and mm (1n,m1000001 \leq n ,m\leq 100\,000), denoting the number of functions and the number of operations. Each of the following nn lines contains two integers aia_i and bib_i (1ai50000,1bi10181\leq a_i\leq 50\,000,1\leq b_i\leq 10^{18}), denoting the ii-th function fi(x)f_i(x). Each of the next mm lines describes an operation in formats described in the statement above.

Output

For each query, print a single line containing an integer, denoting the minimum value of fi(x)f_i(x). Note that when there is no functions, print "-1\texttt{-1}" instead.

Sample Input

1
2 8
3 9
6 100
3 4
2 1
3 4
1 1 1
3 4
2 2
2 3
3 4

Sample Output

10
116
82
-1

Source

2020 Multi-University Training Contest 2