{"raw_statement":[{"iden":"problem statement","content":"Given are integer sequences $A = (a_1, a_2, \\dots, a_N)$, $T = (t_1, t_2, \\dots, t_N)$, and $X = (x_1, x_2, \\dots, x_Q)$.  \nLet us define $N$ functions $f_1(x), f_2(x), \\dots, f_N(x)$ as follows:\n$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}$\nFor each $i = 1, 2, \\dots, Q$, find $f_N( \\dots f_2(f_1(x_i)) \\dots )$."},{"iden":"constraints","content":"*   All values in input are integers.\n*   $1 ≤ N ≤ 2 \\times 10^5$\n*   $1 ≤ Q ≤ 2 \\times 10^5$\n*   $|a_i| ≤ 10^9$\n*   $1 ≤ t_i ≤ 3$\n*   $|x_i| ≤ 10^9$"},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$\n$a_1$ $t_1$\n$a_2$ $t_2$\n$\\vdots$\n$a_N$ $t_N$\n$Q$\n$x_1$ $x_2$ $\\cdots$ $x_Q$"},{"iden":"sample input 1","content":"3\n-10 2\n10 1\n10 3\n5\n-15 -10 -5 0 5"},{"iden":"sample output 1","content":"0\n0\n5\n10\n10\n\nWe have $f_1(x) = \\max(x, -10), f_2(x) = x + 10, f_3(x) = \\min(x, 10)$, thus:\n\n*   $f_3(f_2(f_1(-15))) = 0$\n*   $f_3(f_2(f_1(-10))) = 0$\n*   $f_3(f_2(f_1(-5))) = 5$\n*   $f_3(f_2(f_1(0))) = 10$\n*   $f_3(f_2(f_1(5))) = 10$"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}