An institute has examinations going on and therefore question papers need to be made. The institute has a poor history of students copying from each other and therefore every student is given a separate question paper made from a question bank. Every student should get exactly k questions. Every question can be given to a maximum of 1 student. So, no two students can have any question common among themselves. The question papers are made by a TA, on behalf on an instructor. The affinity of a question to a student is defined by the absolute difference between the question number ID (integer) and the numeric form of the roll number (of the form 1234567, where abc are characters and 1234567 can be any digit). In case of a tie a smaller question number (primary) and a smaller roll number (secondary) are preferred. Print the question paper for every student in the order that the students enter the room.
Input format
The first number is the number of test cases. Every test case starts with q (the number of questions), n (the number of students) and k (the number of questions per student). Thereafter there are q lines of input, each line denoting question ID and question string (1 word). Thereafter there are n lines of input, denoting the student roll number and name (1 word). Thereafter, there are n lines, each line printing the student’s roll number in the order that the students enter the room.
Output Format
For every student, in the order of entry, print the student roll number followed by all questions (without IDs) on new lines.