At the magic fair, magicians keep walking into the main hall and walking back out of it. The strength of every magician is known, and two different magicians may well be equally strong.
From time to time the organizers want to hire someone for a trick, so they ask for the strength of the weakest magician currently in the hall, or for the strength of the strongest one. Write a program that answers those questions.
Input
First line of input will be a single integer - the number of testcases.
First line of each testcase contains an integer - the number of events.
Each of the next lines contains one event, in one of four forms:
i x- a magician of strength walked into the hall;e x- a magician of strength walked out of the hall;m- print the strength of the weakest magician in the hall;M- print the strength of the strongest magician in the hall.
An event e x appears only when a magician of strength really is in the hall, and it removes exactly one of them.
Output
For every event m or M, in the order the events appear, print the requested strength on its own line. If the hall is empty at that moment, print - instead.
Example
1 12 i 1 i 5 i 5 i 8 m e 5 e 8 M e 5 M e 1 m
1 5 1 -
The hall first fills up with strengths , so the weakest is . After one magician of strength and the one of strength leave, the hall holds and - note that the other magician of strength is still there, so the strongest is . Once he leaves too only remains, and after he leaves the hall is empty.
Constraints
the sum of over all testcases does not exceed
This problem was adapted, with permission, from Najjači mađioničar, authored by Društvo matematičara Srbije and Fondacija Petlja.