#P9393. 紫丁香

紫丁香

Problem Description

For a string AA, let AiA_i denote its ii-th character.

Let SS be a 0101 string of length mm. We have nn operations. The ii-th operation can be represented as a function fif_i whose domain and codomain are both the set of length-mm 0101 strings, meaning that after this operation, SS becomes fi(S)f_i(S). The function fif_i can be described by a length-mm string TiT_i, where TiT_i consists of the three characters 0,1,-\texttt{0,1,-}, and:

  • Ti,j=0T_{i,j}=\texttt{0} means [fi(S)]j=0[f_i(S)]_j=\texttt{0}.

  • Ti,j=1T_{i,j}=\texttt{1} means [fi(S)]j=1[f_i(S)]_j=\texttt{1}.

  • Ti,j=-T_{i,j}=\texttt{-} means [fi(S)]j=Sj[f_i(S)]_j=S_j.

That is, each operation sets some bits of SS to 00, some bits to 11, and leaves the remaining bits unchanged.

Now there are qq queries. In each query, you are given a length-mm 0101 string SS. You may apply the operations any number of times, in any order, and an operation may be used multiple times. The resulting string SS' can be viewed as a binary number. Find the SS' that corresponds to the maximum possible binary number.

Input Format

The first line contains three integers m,n,qm,n,q.

The next nn lines: each line contains a length-mm string TT, describing an operation.

The next qq lines: each line contains a length-mm string SS, describing a query.

Output Format

Output qq lines: each line contains a length-mm string, giving the answer to each query in order.

5 3 3
-1-01
011-0
--010
00000
10010
00101

01110
11010
01110

Hint

Sample Explanation

For the first query string 00000\texttt{00000}, you can apply operations 3,23,2 in order to obtain the optimal SS':

$$\texttt{00000}\to \texttt{00010}\to \texttt{01110}$$

For the second query string 10010\texttt{10010}, you can apply operations 1,31,3 in order to obtain the optimal SS':

$$\texttt{10010}\to \texttt{11001}\to \texttt{11010}$$

For the third query string 00101\texttt{00101}, you can apply operations 3,23,2 in order to obtain the optimal SS':

$$\texttt{00101}\to \texttt{00010}\to \texttt{01110}$$

Constraints

For all testdata: 1m221\leq m\leq 22, 1n,q1051\leq n,q\leq 10^5. TT contains only 0,1,-\texttt{0,1,-}, and SS contains only 0,1\texttt{0,1}.

Subtask ID mm\leq nn\leq qq\leq Special Property Score
Subtask 1\text{Subtask 1} 1010 10001000 11 None 1010
Subtask 2\text{Subtask 2} 10001000 2020
Subtask 3\text{Subtask 3} 2020 10510^5 No -\texttt{-} in TT 1010
Subtask 4\text{Subtask 4} 1818 1000010000 1010 None 1818
Subtask 5\text{Subtask 5} 2020 10510^5
Subtask 6\text{Subtask 6} 2222 10510^5 2424

Translated by ChatGPT 5