# #553. 「LibreOJ Round #8」MINIM

#### 题目描述

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 .

#### 输出格式

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


#### 数据范围与提示

-
- 对于每个 存在非负整数 满足

-

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
-