Selecting the Ten Best Teachers

No attempts yetTime limit1sMemory limit128 MB

Problem

A school picks its ten best teachers out of nn teachers (n50n \le 50) by a secret ballot among the students.

The teachers are numbered continuously starting at 1, and every number is written with two characters: 01, 02, 03 and so on.

One ballot lists the numbers of ten selected teachers. The position a number sits in is the place that ballot gives the teacher. A place may be left empty, and an empty place is written as 00. A ballot is discarded when it holds a number outside the range 01 to nn, or when the same teacher number appears twice or more. The empty marker 00 may repeat as often as it likes and never discards a ballot.

Each place carries a score.

PlaceFirstSecondThirdFourthFifthSixthSeventhEighthNinthTenth
Score151297654321

The vote count of a teacher is the number of accepted ballots that write that teacher into a place other than an empty one. Sort the teachers by total score, from high to low. Two teachers on the same score are ordered by vote count, the larger one first. When the score and the vote count are both equal, the smaller teacher number comes first.

Input

The first line holds two integers nn and mm separated by a space: the number of teachers and the number of ballots.

Each of the next nn lines describes one teacher as a number, a name, and a department, separated by single spaces. The teacher lines may arrive in any order, and no name or department contains a space. Names are at most 15 characters long and departments at most 37.

Each of the next mm lines holds one ballot, a string of exactly 20 characters made of ten two-digit numbers.

The last line is -1.

Output

Print the first min(n,10)\min(n, 10) teachers of the sorted order, one per line. Each line joins the following fields with no separator between them.

  • the rank, counted from 1, left aligned in 4 columns
  • the two-digit teacher number, left aligned in 4 columns
  • the name, left aligned in 15 columns
  • the department, left aligned in 37 columns
  • twelve integers, each right aligned in 6 columns, in this order: the total score, the vote count, then how many first places the teacher took, how many second places, and so on down to how many tenth places

A field shorter than its width is padded with spaces, so every printed line is 132 characters long.