QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100 可 Hack ✓

#11416. The nail that sticks out gets hammered down

统计

The great NIT loves using XOR to represent all things in the world. For a multiset $A$ consisting of non-negative integers (i.e., a set where elements may repeat), we say that the multiset $A$ can represent an integer $x$ if and only if $x$ can be written as the XOR sum of some elements in $A$. That is, there exists a set of numbers $a_1, a_2, \dots, a_k$ ($k \ge 0$), where each element $a_i$ belongs to the multiset $A$, such that $a_1 \oplus a_2 \oplus \cdots \oplus a_k = x$. Here, $\oplus$ denotes the XOR operation.

The great NIT loves multisets. The great NIT has $n$ multisets, numbered $1$ to $n$. He hopes that each multiset is self-reliant and capable of representing every non-negative integer in the world. Therefore, the great NIT will continuously examine these multisets.

There are $Q$ examinations in total. In each examination, the great NIT provides an integer $x$, and then sequentially checks the multisets numbered $1, 2, 3, \dots$ to see if each can represent $x$. If a multiset cannot represent $x$, the great NIT will punish the multiset with the smallest index that failed the check.

After many examinations, the great NIT became weary. Thus, he turned to you. For each examined number $x$, he wants you to find the smallest $\mathrm{ans}$ such that all multisets with an index less than $\mathrm{ans}$ can represent $x$, but the $\mathrm{ans}$-th multiset cannot represent $x$.

Specifically, if all multisets can represent $x$, then $\mathrm{ans} = n+1$. For example, by definition, any multiset can represent $0$, so for $x=0$, $\mathrm{ans} = n+1$.

Input

The first line contains two integers $n$ and $Q$, representing the number of multisets and the number of queries, respectively.

The next $n$ lines each describe a multiset. The first number in each line is $K$, representing the number of elements in the multiset. The following $K$ numbers are the elements of the multiset.

The next $Q$ lines each contain a single integer, representing an examination.

Output

Output $Q$ lines, each containing an integer from $1$ to $n+1$ representing the answer.

Examples

Input 1

3 2
4 2744 1021136488 2329479997782303641 935 
4 2 4 935 2329479998801208554 
4 4 51 27 11 
2329479998801208558
2329479997782302782

Output 1

3
2

Note 1

For the first query, $2329479998801208558=2744\oplus 1021136488\oplus 2329479997782303641\oplus 935=4\oplus 2329479998801208554$, but it cannot be represented by the third multiset.

For the second query, $2329479997782302782=2329479997782303641\oplus 935$, but it cannot be represented by the second multiset.

Input 2

10 10
10 4260028 34 639922 270 159 204186869390 7872512053053 146273753867518431 7402239233637956033 1286201783702553613 
10 639888 146273648742309091 1 35 4 297 4768557 7872511544459 1431631938076805321 7402244836586944365 
10 1 34 639922 7872507924386 2 4259997 269 146274849013224144 1286207269115909678 8602877971614658540 
10 14 5 1 38 290 4259995 639632 7872507924134 7259140066259904901 1286207269119529986 
10 5 17 297 169 54 4260126 639538 1286201669723691316 7872512053140 8458925429369601838 
10 34 1 2 5 1286201669724199554 300 7872507284533 639924 8458926633202364454 4768258 
10 1 17 316 34 4411 12559 1286201669724199601 647867 7872507928250 8458925429369597578 
10 2 12 7 41 69 255 290 615 7872507284756 639164 
10 34 1 3 270 78 12 2103 21831 12353 780 
10 14 2 578 12320 1 79 28543 89652 45244 368987 
8458926633201955485
8458925530406871954
7259140066259904674
8458926633206084129
7259140066259904573
8602877971614018898
8602877971614018898
8602877971618787311
1286207181167823279
1431631938081065198

Output 2

8
2
7
7
2
4
4
2
2
2

Constraints

Subtask $n\leqslant $ $Q\leqslant $ $K_i\leqslant $ Score
$1$ $10^3$ $10^3$ $64$ $31$
$2$ $10^5$ $10^6$ $20$ $32$
$3$ $64$ $37$

For all data, it is guaranteed that $\sum K_i\leqslant 10^6, 1\leq n\leq 10^5, 1\leq Q\leq 10^6, 1\leq K_i\leq 64, 0\leq a_i, x < 2^{64}$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.