Many residents of Bitaculandia participate in the stages of international programming olympiads. There are seven such olympiads held in Bitaculandia:
Miss M is responsible for organizing various stages of olympiads, as well as selections (training camps) for all seven international stages. After the last selection round, teams of four to six people are formed for all seven olympiads. However, only those participants who meet the criteria for participation in the olympiad should be sent to each competition. Here is a list of algorithms for determining the participants of the teams for the olympiads:
If there are fewer participants than the required number, it means that the team will consist of fewer people. For example, if you need to determine the team for EGOI and there are only two girls, it means that the team will consist of only two participants, not four.
Since there are many participants and many olympiads, and the results are desired immediately after the competition ends, Miss M asks to write a program that, based on the results and information about the participants, provides the composition of the teams for the international stages of the olympiads.
The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 10^{4}$$$) — the number of olympiad participants.
Each of the following $$$n$$$ lines contains information about the olympiad participants:
It is guaranteed that all $$$id$$$ and $$$score$$$ of participants are different.
The next line contains an integer $$$m$$$ ($$$1 \leq m \leq 7$$$) — the number of international olympiads for which Miss M wants to know the composition of the participant teams.
The following $$$m$$$ lines contain the names of the international olympiads for which the composition of the participant teams needs to be output. Possible olympiads: IOI, CEOI, EGOI, EJOI, BaltOI, BalkOI, JBOI. It is guaranteed that all olympiads are different.
Output $$$m$$$ lines, containing the names of the international olympiads, in the same order as specified in the input data, and the $$$id$$$ of participants who are part of the teams, in the format of increasing participant $$$id$$$ number.
In this problem, there are tests where $$$m=1$$$ for each possible olympiad. That is, if you can only solve the problem for a certain olympiad, you are guaranteed to receive points.
101000001 female 10 16 4001000002 male 10 17 5001000003 male 11 17 5051000004 male 11 16 4051000005 female 11 17 4501000006 female 10 15 4801000007 male 9 15 4451000008 male 6 12 3501000009 male 8 13 3991000010 male 10 16 4303IOIEGOIBaltOI
IOI 1000002 1000003 1000005 1000006 EGOI 1000001 1000005 1000006 BaltOI 1000002 1000003 1000005 1000006 1000007 1000010
All participants can take part in IOI, the results table will look like this:
The participants who will go to the olympiad are $$$1000003$$$, $$$1000002$$$, $$$1000006$$$, $$$1000005$$$.
Only girls can participate in EGOI, the results table will look like this:
The participants who will go to the olympiad are $$$1000006$$$, $$$1000005$$$, $$$1000001$$$.
All participants can take part in BaltOI, the results table will look the same as for IOI. The same participants who will go to IOI will also go to BaltOI, as well as $$$1000007$$$ and $$$1000010$$$.