This page is still under construction.

Parts of this page are still being built. What you see may change.

Basic Basis

Time limit1sMemory limit512 MB

Summary
Given n bit vectors of 4k bits, for each of m query vectors find the smallest prefix index i such that some nonempty subset of the first i vectors XORs to the query.
Level

Hard8 of 10

Topics
Math, Bit manipulation, Greedy, Implementation
Solved
No attempts yet

Problem

You are given a sequence of nn bit strings b1,b2,…,bnb_1, b_2, \dots, b_n, each with k×4k \times 4 bits.

You are also given another sequence of mm bit strings a1,a2,…,ama_1, a_2, \dots, a_m, each also with k×4k \times 4 bits.

Let f(x)f(x) denote the minimum index ii such that it is possible to take a non-empty subset of b1,b2,…,bib_1, b_2, \dots, b_i, XOR them all together, and get xx. If there is no such index, f(x)=−1f(x) = -1.

Print the values f(a1),f(a2),…,f(am)f(a_1), f(a_2), \dots, f(a_m).

Input

The first line of input contains three integers nn (1≤n≤1,0001 \le n \le 1,000), mm (1≤m≤1,0001 \le m \le 1,000) and kk (1≤k≤401 \le k \le 40), where nn is the length of sequence bb, mm is the length of sequence aa, and the elements of both sequences are bit strings with k×4k \times 4 bits.

Each of the next nn lines contains a hexadecimal representation of bib_i as a string of length kk. The strings consist only of hexadecimal digits (‘0’–‘9’ and ‘a’–‘f’).

Then, each of the next mm lines contains a hexadecimal representation of aia_i in the same format as above.

Output

Output mm lines with a single integer on each line, where the integer on the iith line is f(ai)f(a_i).

Examples2

  1. Example 1

    Input
    3 5 2
    02
    e1
    fa
    02
    e3
    1b
    e1
    ff
    
    Expected output
    1
    2
    3
    2
    -1
    
  2. Example 2

    Input
    5 6 2
    01
    02
    04
    08
    10
    01
    02
    03
    04
    05
    64
    
    Expected output
    1
    2
    2
    3
    3
    -1