University Entrance Examination

No attempts yetTime limit1sMemory limit128 MB

Problem

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 NN students S1,,SNS_1, \dots, S_N and MM programs F1,,FMF_1, \dots, F_M. 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.

  1. Local-student rule. Consider two students AA and BB who both listed a program FF located in region RR, and suppose score(A)>score(B)\mathrm{score}(A) > \mathrm{score}(B). If BB is local to FF (its home region is RR), AA is non-local (home region other than RR), and score(B)>0.7score(A)\mathrm{score}(B) > 0.7 \cdot \mathrm{score}(A), then BB has priority over AA for FF. In every other case AA has priority over BB for FF.
  2. Fairness rule. Each accepted student is placed in the earliest program on their own priority list that they can actually enter.

All scores are distinct integers.

Input

The first line contains an integer tt (1t101 \le t \le 10), the number of test cases. Each test case is given as follows.

The first line contains two integers NN (1N1501 \le N \le 150) and MM (1M501 \le M \le 50).

Each of the next NN lines describes one student SiS_i in the form Ri  Mi  K  Fi1    FiKR_i \; M_i \; K \; F_{i1} \; \dots \; F_{iK}, where RiR_i is the student's home region number, MiM_i is their exam score, KK (0KM0 \le K \le M) is the length of their priority list, and Fi1,,FiKF_{i1}, \dots, F_{iK} are the program numbers in order of preference.

Each of the next MM lines describes one program FjF_j as two integers RjR_j and CjC_j: the region number of FjF_j and its capacity.

Region numbers are arbitrary integers.

Output

For each test case, print NN lines, one per student in input order. On the ii-th line print jj if student SiS_i is accepted into program FjF_j, 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.