Fence
For the park of culture and recreation, a decision was made to construct a decorative fence that complements the city's aesthetic. Architects designed several templates for the fence sections, each shaped as a polygon with three fixed sides and a fourth side forming a zigzag pattern. The vertices of this zigzag are evenly spaced along the base of the fence, and the template is defined by a sequence of point heights. These heights are given in whole millimeters, ranging from 0 to 2047.
The template consists of L points (1 <= L <= 10000). The architects created M templates (1 <= M <= 10000), and the factory produced N sections based on these templates (N <= 10000000). An example of a section with L = 7 is illustrated in the figure.
Unfortunately, during transportation to the park, an accident caused the fence sections to scatter and mix. As the sections were sorted from the debris, their measurements were taken. Now, using these measurements, it is necessary to identify which template each section corresponds to. Additionally, some sections may have been damaged (e.g., broken teeth), so it's important to count sections that do not match any template.
The task is simplified by the fact that the inner side of the section, which faces the park, is a different color from the outer side. This ensures that the height measurements are in the same order as in the template.
Input
All data is separated by a single space, with each line ending with a newline character.
The first line contains the number of tests. Following this, the test data is provided.
The first line of each test contains the values L (the number of points in the template and section), M (the number of different templates), and N (the number of sections found).
Next, M lines provide information about each template: the template number (a natural number) and L points of the template.
Following this, N lines provide information about the fence sections, with each line containing L points for one section.
Output
The first line should output the word TEST followed by the test number, separated by a space.
Then, for each of the N lines, output the template number that matches the section. If no matching template is found, output the dash symbol '-'.
In the final line of each test, output the word "OK=" (without quotes) followed by the number of sections that matched templates, then "BAD=" followed by the number of damaged sections.