Hazel's Harvest

Hazel is starting a tree plantation. She likes to plan ahead and has prepared a planting schedule for NN trees.

The trees will be grown elsewhere before being moved to Hazel’s plantation. Each tree will be planted there in a specific year YY, when it will already be HH meters tall. Once planted, it remains in the plantation and grows exactly one meter per year. Thus, in any year t≥Yt \ge Y, the tree is H+t−YH + t - Y meters tall.

To plan her future sales, Hazel considers QQ potential purchase orders for trees. Each order requests KK trees, each at least VV meters tall. An order can be fulfilled in a given year if the plantation has at least KK planted trees that are each at least VV meters tall.

The orders are independent: no trees are actually removed from the plantation, and each order is considered as if it were the only one. For each order, determine the earliest year in which it could be fulfilled.

Input

The first line contains an integer NN (1≤N≤2×1051 \le N \le 2 \times 10^{5}) representing the number of trees in the planting schedule.

Each of the next NN lines describes a tree with two integers YY and HH (1≤Y,H≤1091 \le Y, H \le 10^{9}), indicating respectively its planting year and its height in meters when planted.

The next line contains an integer QQ (1≤Q≤2×1051 \le Q \le 2 \times 10^{5}) representing the number of purchase orders.

Each of the next QQ lines describes a purchase order with two integers KK (1≤K≤N1 \le K \le N) and VV (1≤V≤10181 \le V \le 10^{18}), indicating respectively the number of trees requested and their minimum height in meters.

Output

For each purchase order in the input, output a line with an integer indicating the earliest year in which it could be fulfilled. It can be shown that an answer exists for each purchase order.

Examples

Input

3
1 5
6 10
3 2
3
2 4
1 11
3 1

Output

5
7
6

Explanation

For the first order (K = 2, V = 4), the first tree is already tall enough when it is planted in year 1. The third tree reaches a height of 4 meters in year 5, while the second tree has not yet been planted. Therefore, the earliest year in which the order could be fulfilled is 5.

For the second order (K = 1, V = 11), the first two trees reach a height of 11 meters in year 7, while the third tree reaches that height in year 12. Therefore, the answer is 7.

For the third order (K = 3, V = 1), every tree is tall enough from the year it is planted. However, the second tree is not in the plantation before year 6. Therefore, the answer is 6.

Input

2
5 8
5 8
3
2 8
1 10
1 8

Output

5
7
5

Explanation

Both trees are planted in year 5, when they are already 8 meters tall. They are separate trees, so the first order (K = 2, V = 8) could be fulfilled in year 5, but not earlier.

Both trees reach a height of 10 meters in year 7, the answer to the second order (K = 1, V = 10).

The third order (K = 1, V = 8) could be fulfilled in year 5: orders are considered independently, so neither of the previous orders removes any trees.