Under construction

Still being built. Things may change

Books

Time limit6sMemory limit1024 MB

Summary
For each candidate pair of students, find every book set whose books the two students can jointly cover, splitting the books between them.
Level

Hard8 of 10

Topics
Bit manipulation, Dynamic programming
Solved
No attempts yet

Problem

The Noname State University (NSU) is preparing for a new type of programming contest. Each university in this contest can be represented only by a single team of two students. There is also the official list of NN books which the contestants must read to perform successfully. There is little time left before the contest, and not every student is able to read all books in time.

Every student knows for each set of books whether she can read it in time. There are MM students willing to participate in the contest in the NSU. The coach prepared a list of KK candidate teams. To choose a single team for the contest, she wants to know each team's reading capability.

A team has read a book if at least one member of the team has read it. Your task is to find, for each candidate team and for each set of books, whether the team members can plan their training so that the team will have read all the books of this set in time.

Input

The first line of the input contains three integers: NN (number of books), MM (number of students), and KK (number of candidate teams). The constraints are 1≤N≤211 \le N \le 21, 2≤M≤62 \le M \le 6, and 1≤K≤61 \le K \le 6. Zero-based numbering is used everywhere in this problem.

The ii-th of the next MM lines defines the capabilities of the ii-th student. The capabilities are a string SiS_i of length 2N2^N containing 0's and 1's. The kk-th character of the string is 1 if and only if the student can read the set of books with bitmask kk in time. The bitmask is defined as follows.

Number the books from 0 to N−1N-1. Let XX be a set of books, and let aj=1a_j = 1 if book jj belongs to XX, and aj=0a_j = 0 otherwise. The bitmask of XX is k=∑j=0N−1aj2j.k = \sum_{j=0}^{N-1} a_j 2^j. The ii-th student can read XX in time if and only if the kk-th character of SiS_i is 1.

The tt-th of the next KK lines describes the tt-th candidate team. It contains two integers ata_t and btb_t, the numbers of the two students in the team (0≤at,bt<M0 \le a_t, b_t < M, at≠bta_t \neq b_t).

The capabilities satisfy two guarantees. First, if a student can read a set of books, she can read every subset of it. Second, a student can always read the empty set, so the first character of her string is always 1.

Output

Print KK lines, each containing 2N2^N characters 0 or 1. The tt-th line gives the capabilities of the tt-th team in the same format as the students' strings in the input. The kk-th character of the tt-th line is 1 if and only if the team can read the set XX of books with bitmask kk in time.

Hint

The 0-th student can read one of the following sets: ∅\emptyset, {0}\{0\}, {1}\{1\}, {2}\{2\}, {0,1}\{0, 1\}, {1,2}\{1, 2\}. The first student can only read book 0 (or nothing). The second student can read either book 0 or book 2 (or nothing). The third and fourth students can read any single book (or nothing).

The 0-th team is able to read all the books if student 0 reads books {1,2}\{1, 2\} and student 1 reads book 0. It is easy to check that the team can also read any other set of books.

The 1st team can read books 0 and 2 if its members read different books. The team can also read any subset of {0,2}\{0, 2\}.

In the 2nd team, each member can read at most one book. Hence, the team together can read any set of two or fewer books.

Examples1

  1. Example 1

    Input
    3 5 3
    11111010
    11000000
    11001000
    11101000
    11101000
    0 1
    1 2
    3 4
    
    Expected output
    11111111
    11001100
    11111110