Hostel Nights

No attempts yetTime limit1sMemory limit128 MB

Problem

The students living on the first floor of a hostel are known for being a bit too noisy. Over the 5 nights of one week, the warden investigates the noise reports. The other students will not name a floor-mate directly, but they help by ruling out rooms whose student was not noisy on a given night. On each night a room is eliminated if any one of three conditions holds:

  1. Room-number parity: E eliminates even-numbered rooms, O eliminates odd-numbered rooms.
  2. The room number is a multiple of a given number $n$.
  3. The student's name begins with a given letter.

For each of the 5 nights the warden is given these three conditions. After the 5 nights he can identify the noisiest students: those who were not eliminated on the greatest number of nights. Because this floor is notorious, there is always at least one such student.

Input

The first line contains a single integer $W$, the number of weeks of data (each week is 5 nights).

The data for each week begins with 20 lines, each containing a room number and a student's name separated by a space. Rooms are numbered from 101 to 120. Each student is a single name.

These 20 lines are followed by 5 lines, one per night. Each line contains a letter, a number, and a letter, separated by spaces. The first letter is E or O and says whether even (E) or odd (O) numbered rooms are eliminated. The number eliminates every room whose number is a multiple of it. The second letter eliminates every student whose name begins with that letter.

Output

For each week, first print the week number as Week k, where the first week is 1. Then print the noisiest students — those not eliminated on the greatest number of nights — one name per line, in increasing room-number order.