Every year a huge number of high-school graduates compete for a limited number of university places through a single, centralized national entrance examination, run by the Education Evaluation Organization (EEO). After the exam, each eligible participant submits a priority list of the Field-Department-University programs (FDUs) they want to join, ordered from most to least preferred. Using each participant's total score, their priority list, and the selection rules below, the EEO fills every FDU up to its capacity. One selection goal is to encourage students to attend universities near their home region, which reduces demand for dormitories. Each accepted participant is placed in exactly one FDU; anyone not placed in any FDU on their list has failed.
You are given N students S1,…,SN and M programs F1,…,FM. Each student has a total score, a home geographic region (the region where their high-school diploma was awarded), and a priority list of the programs they want. Each program has a geographic region (where its university is located) and a capacity for the year.
Assign students to programs so that both rules below hold.
All scores are distinct integers.
The first line contains an integer t (1≤t≤10), the number of test cases. Each test case is given as follows.
The first line contains two integers N (1≤N≤150) and M (1≤M≤50).
Each of the next N lines describes one student Si in the form RiMiKFi1…FiK, where Ri is the student's home region number, Mi is their exam score, K (0≤K≤M) is the length of their priority list, and Fi1,…,FiK are the program numbers in order of preference.
Each of the next M lines describes one program Fj as two integers Rj and Cj: the region number of Fj and its capacity.
Region numbers are arbitrary integers.
For each test case, print N lines, one per student in input order. On the i-th line print j if student Si is accepted into program Fj, or not accepted if the student is not admitted to any program on their list.
Print exactly one blank line between the outputs of consecutive test cases.