Олимпиадный тренинг

Задача 21816. Saruman


Задача

Темы:
As you know, Saruman the White is a very busy magician and every day he has to work with a huge amount of ancient scrolls. To avoid confusion, he gave each scroll a number and placed them all on a long shelf. But lately, Gandalf has been constantly visiting him to learn something from the scrolls, which pleases Gandalf and infuriates Saruman very much. And in order not to answer a huge number of Gandalf's questions where everything is, he promised to give his staff to the one who writes a program that answers Gandalf's questions.
 
Input:
The first line contains the number N(0<=N<=105). The next N lines contain a description of the scroll type and its number L (-109<=L<=109). Then enter the number Q(0<=N<=105) – number of requests. And then on more Q lines, the scroll type and number are entered (-105<=L<=105).
Scroll types:
LEG - legendary
FEW - rare
STAND – normal
 
Imprint:
For each request, display the position of the scroll if it exists (Numbering from 1) and “Fatality error” if there is none. Each answer is on a new line. Gandalf is also interested in the number of the largest scroll and the smallest one (the type of scroll does not affect this). This must be output after the main queries on a new line, as in the example.
 
Example:
Input:
5
LEG-345
LEG 1
FEW 2452
STAND 4
FEW 334
3
LEG-353
LEG-345
STAND 4
Imprint:
Fatality error
1
4
Max 2452 Min -345

Author: Aksenov Vladimir