#abc287g. [abc287_g]Balance Update Query

[abc287_g]Balance Update Query

Problem Statement

Takahashi has 1010010^{100} cards of each of NN kinds. Initially, the score and quota of the ii-th kind of card are set to aia_i and bib_i, respectively.

Given QQ queries in the following formats, process them in order.

  • 1 x y: set the score of the xx-th kind of card to yy.
  • 2 x y: set the quota of the xx-th kind of card to yy.
  • 3 x: if one can choose xx cards subject to the following condition, print the maximum possible sum of the scores of the chosen cards; print -1 otherwise.
    • The number of chosen cards of each kind does not exceed its quota.

Constraints

  • 1leqN,Qleq2times1051 \\leq N,Q \\leq 2 \\times 10^5
  • 0leqaileq1090 \\leq a_i \\leq 10^9
  • 0leqbileq1040 \\leq b_i \\leq 10^4
  • For each query of the 11-st kind, 1leqxleqN1 \\leq x \\leq N and 0leqyleq1090 \\leq y \\leq 10^9.
  • For each query of the 22-nd kind, 1leqxleqN1 \\leq x \\leq N and 0leqyleq1040 \\leq y \\leq 10^4.
  • For each query of the 33-rd kind, 1leqxleq1091 \\leq x \\leq 10^9.
  • There is at least one query of the 33-rd kind.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format, where mathrmqueryi\\mathrm{query}_i denotes the ii-th query:

NN a1a_1 b1b_1 vdots\\vdots aNa_N bNb_N QQ mathrmquery1\\mathrm{query}_1 vdots\\vdots mathrmqueryQ\\mathrm{query}_Q

Output

Print MM lines, where MM is the number of queries of the 33-rd kind.
The ii-th line should contain the response to the ii-th such query.


Sample Input 1

3
1 1
2 2
3 3
7
3 4
1 1 10
3 4
2 1 0
2 3 0
3 4
3 2

Sample Output 1

11
19
-1
4

For the first query of the 33-rd kind, you can choose one card of the 22-nd kind and three cards of the 33-rd kind for a total score of 1111, which is the maximum.
For the second such query, you can choose one card of the 11-st kind and three cards of the 33-rd kind for a total score of 1919, which is the maximum.
For the third such query, you cannot choose four cards, so -1 should be printed.
For the fourth such query, you can choose two cards of the 22-nd kind for a total score of 44, which is the maximum.