"CodeSavages" is a very renowned online judge (Contest Platform) in these days. They provide an initial rating to every contestant and after each contest, they increase or decrease their rating point based on their performance of that contest. They also provide a rank to the user based on their rating point. Rank of a user changes if he gets into another range because of the rating changes after contests. "CodeSavages" shows two things to the user - his current rank and his best rank of all time.
Suppose Ranking Ranges are -
0 to 1199 - Newbie
1200 to 1399 - Pupil
1400 to 1599 - Specialist
Suppose, someone’s rating point is 1451. So his rank is Specialist. He has participated in a contest and his rating point has decreased by 61 points. So his new rating will be 1451-61=1390. Now his current rank will be Pupil and best rank will be Specialist.
"Mojnu" is a great contestant. He is now in an honorable rank on "CodeSavage.com". But recently "Mojnu" suspect that there might have been some bugs with the ranking system of "CodeSavage". He wants to justify it before the next contest, so he can tell the admins of "CodeSavage" about that. But there is only one day left before the next contest but he already has a date with his girlfriend "Laaily". He can’t cancel this because he is very much afraid of "Laaily". So he asks for your help.
He needs a program that will take the following things as input -
Ranking Ranges.
"Mojnu’s" initial rating.
The number of contests he has participated and rating changes of those contests.
And for every rating changes of given contests, it will output two things.
His Current Rank.
His Best Rank so Far.
For better understanding, please see the input/output section.
And, please don’t turn your back on “Mojnu”. If you don’t help him he can’t go for a date and “Laaily” will break up with him.
The first line contains the number of Ranking Ranges N(1<=N<=10).
Each of the next N lines will contain two integers A, B and a string S separated with a single space. Here A is the lower and B is the upper bound of this range and S is the name of the rank for rating point in the range of A and B.
(0<=A<=B<=9999) (1<=|S|<=15). |S| means length of S.
The next line contains the initial rating R (0<=R<=9999).
The next line contains P (1<=P<=100) - the number of contests he has participated.
Each of the next P lines will contain two integer C and K(0<=k<=400).
C will be either 0 or 1.
If C is 0, his rating has been decreased by K points.
If C is 1, his rating has been increased by K points.
It is guaranteed that the ranking ranges will be in increasing order according to the rating points and the initial rating and rating changes will be given in a way such that the rating point will always be in the given ranking ranges.
For each rating point changes, you have to output two things – His Current Rank and His Best Rank so far separated by a single space.
Input | Output |
---|---|
5 0 1199 Newbie 1200 1399 Pupil 1400 1599 Specialist 1600 1799 Expert 1800 2099 CandidateMaster 1500 5 1 99 0 109 0 11 1 131 0 36 | Specialist Specialist Specialist Specialist Specialist Specialist Expert Expert Specialist Expert |