#C7013. Finding the Best Moments

    ID: 50838 Type: Default 1000ms 256MiB

Finding the Best Moments

Finding the Best Moments

You are given information about a set of attributes, users and moments. Each user has a preference, which is a list of tags for each attribute, and each moment is characterized by a list of tags corresponding to these attributes. The task is to choose the best moment for each user. The quality of a moment for a user is determined by the number of attributes for which the moment's tag matches the user's preference.

More formally, let \(N\) be the number of attributes. For each user \(i\) with preferences \(u_i=[u_{i1}, u_{i2}, \dots, u_{iN}]\) and each moment \(j\) with tags \(m_j=[m_{j1}, m_{j2}, \dots, m_{jN}]\), define the score of moment \(j\) for user \(i\) as:

[ score(i,j)=\sum_{k=1}^{N} \mathbf{1}{ m_{jk} = u_{ik} }, ]

Your objective is to output, for each user, the 1-based index of the moment with the highest score. In the case of a tie, choose the moment that appears first in the input.

inputFormat

The input is given from standard input (stdin) with the following format:

N M K

where \(N\) is the number of attributes, \(M\) is the maximum number of possible tags for an attribute (not necessarily used directly), and \(K\) is the number of users.

This is followed by \(N\) lines describing each attribute. Each of these lines starts with an integer \(L\) (the number of tags for the attribute) followed by \(L\) integers representing the available tags. (Note that the lengths of these attribute lists can vary.)

Then there are \(K\) lines, each containing \(N\) integers; the \(i\)th such line represents the preferred tags of the \(i\)th user for each attribute.

After that, a line containing an integer \(T\) is given, representing the number of moments. This is followed by \(T\) lines, each with \(N\) integers representing the tags of the moment for each attribute.

You may assume that all integers are positive and that the input is well-formed.

outputFormat

Output a single line to standard output (stdout) containing \(K\) integers separated by a space. The \(i\)th integer should be the 1-based index of the best moment for the \(i\)th user.

## sample
3 4 2
4 1 2 3 4
4 2 2 1 3
3 3 4 4
1 3 2
2 3 1
2
1 4 2
2 2 4
1 2

</p>