NIM is a game of strategy in which two players take turns removing stones from distinct piles. On each turn, a player must remove at least one stone, and may remove any number of stones provided they all come from the same pile. The player who has no stones to remove loses.
There are piles of stones, the -th pile has stones. Alice needs to remove some of the stones from each pile (removing zero or all of the stones from a certain pile is allowed). If the -th pile remains at least one stone after this operation, Alice has to pay a price of . After Alice's operation, Bob will create a pile of stones whose number is in and add it to the game to make sure that Alice — the player who moves first in this NIM game will lose.If he can't ensure that Alice will lose,he will exit from the game immediately.
Now Alice has queries. Each query gives an integer , and you need to calculate the minimal total price Alice needs to pay to ensure Bob’s new pile has exactly stones(making Bob exit from the game isn't allowed,even if ). If this is impossible, print -1 instead.
输入格式
第一行两个正整数 。
接下来 行每行两个正整数 表示该堆石子的代价和数量。
接下来一行一个正整数 。
接下来 行每行一个正整数 表示询问。
The first line contains two integers .
Each of the following lines contains two integers .
The next line contains an integer .
Each of the following lines contains an integers .
输出格式
输出共 行,依次表示每次询问的答案,无解输出 -1。
Output contains lines,containing the answer of each query in order.
样例
样例输入
4 6
2 3
4 4
3 5
5 2
7
0
1
2
3
4
5
6
样例输出
0
2
2
2
3
3
5
Sample Input
4 6
2 3
4 4
3 5
5 2
7
0
1
2
3
4
5
6
Sample Output
0
2
2
2
3
3
5
数据范围与提示
对于所有数据,。
详细的数据限制及约定如下(留空表示和上述所有数据的约定相同):
Subtask #
分值(百分比)
特殊性质
-
-
对于每个 存在非负整数 满足
在范围内均匀随机(使用 std::mt19937 并对最大值取模)
-
For all test cases, .
Detailed constraints and hints are as follows (blank grids denote the same constraints as mentioned above):
Subtask #
Score (percentage)
Special Constraints
-
-
are randomly generated in range by std::mt19937 modulo maximum limit