StrCartesian
면접 대비시간 제한13초메모리 제한2048 MB
두 문자열 집합의 모든 n*m개 연결 조합을 사전순으로 정렬한 뒤, k번째 원소의 인덱스 쌍을 답한다.
문제
Given are two sets of strings and . Define a sequence of pairwise concatenations of and :
Now sort the sequence lexicographically, and let the sorted sequence be .
We want to know the sequence , but it is too large. So we make queries to your program, and the -th query asks for .
However, is still too long to output. If the answer equals , then your program only needs to output the pair .
입력
The first line contains two integers and (), the sizes of sets and set .
The following lines contain distinct non-empty strings .
The total length of strings in set does not exceed .
The following lines contain distinct non-empty strings .
The total length of strings in set does not exceed .
All strings consist of lowercase English letters.
The next line contains one integer (), the number of queries.
In the following lines, the -th line contains an integer (), specifying that the query asks for the -th element of .
출력
Print lines. The -th line must contain two integers and (; ) specifying that the answer equals to . If there are multiple correct answers, your program may output any one of them.