Problem Statement
Given are integer sequences A=(a1,a2,dots,aN), T=(t1,t2,dots,tN), and X=(x1,x2,dots,xQ).
Let us define N functions f1(x),f2(x),dots,fN(x) as follows:
$f_i(x) = \\begin{cases} x + a_i & (t_i = 1)\\\\ \\max(x, a_i) & (t_i = 2)\\\\ \\min(x, a_i) & (t_i = 3)\\\\ \\end{cases}$
For each i=1,2,dots,Q, find fN(dotsf2(f1(xi))dots).
Constraints
- All values in input are integers.
- 1≤N≤2times105
- 1≤Q≤2times105
- ∣ai∣≤109
- 1≤ti≤3
- ∣xi∣≤109
Input is given from Standard Input in the following format:
N
a1 t1
a2 t2
vdots
aN tN
Q
x1 x2 cdots xQ
Output
Print Q lines. The i-th line should contain fN(dotsf2(f1(xi))dots).
3
-10 2
10 1
10 3
5
-15 -10 -5 0 5
Sample Output 1
0
0
5
10
10
We have $f_1(x) = \\max(x, -10), f_2(x) = x + 10, f_3(x) = \\min(x, 10)$, thus:
- f3(f2(f1(−15)))=0
- f3(f2(f1(−10)))=0
- f3(f2(f1(−5)))=5
- f3(f2(f1(0)))=10
- f3(f2(f1(5)))=10