Task
We are given three natural numbers , , and , followed by natural numbers of exactly digits each. Each of the numbers is divided into groups of digits each (the last group may not always be exactly digits).
On the next line, the number is given, and on each of the following lines, there are digits separated by spaces. Let these be . We define the power of a number in the sequence as the number of groups () for which appears at least once in the -th group of that number. For each of the lines, output the position of the first number in the sequence that has the maximum power, as well as the maximum power. If the maximum power is , print .
Input data
The first line contains three natural numbers , , and . The next lines contain numbers of digits, one per line. The next line contains the number . The next lines each contain digits separated by spaces.
Output data
The lines will contain at most two numbers, representing the position of the first element with the maximum power and the maximum power, separated by a space. If the maximum power is , print only .
Constraints and clarifications
- ;
- ;
- ;
- Numbers can also start with the digit .
- The sequence of numbers is indexed from .
# | Points | Constraints |
---|---|---|
, | ||
, | ||
, | ||
, | ||
No additional constraints | ||
No additional constraints |
Example 1
stdin
3 3 10
1234581659
2870454321
9561840782
3
4 3 9 5
5 7 3 2
2 4 9 2
stdout
-1
3 2
1 2
Explanation
The numbers divided into groups are:
For the first query, no number contains the digit in the first group, the digit in the second group, the digit in the third group, or the digit in the last group, so is displayed.
For the second query, only the third number contains the digit in the first group, no number contains the digit in the second group, only the second number contains the digit in the third group, and only the third number contains the digit in the last group, so is displayed, as the maximum is and it occurs at the third number.
For the third query, only the first number contains the digit in the first group, all three numbers contain the digit in the second group, no number contains the digit in the third group, and only the last number contains the digit in the last group, so is displayed, as the maximum appears at the first and third numbers, but the first number is displayed first.