Welcome to ZOJ
Information
Problems
Runs
Statistics
Ranklist
Clarification
53 - ZJUPC ZyXel Cup 2006 - 1005
Board Manager Simulation

Time Limit: 2 Seconds      Memory Limit: 65536 KB

This problem is about the board maintenance for board manager in BBS system, such as Freecity site. Here you will be given a list of posts, each post has an ID attribute (means the poster) with at most 12 letters (case sensitive) and a TITLE attribute with at most 30 letter or digit or spaces (case sensitive). Each title will have a prefix "O " or "Re: ". "O " means the first post of this title and "Re: " means the reply for this title. When maintaining the board, the BM (short for board manager) can use 'b' function, which should be simulated here. For 'b' function, here's three parameters means the target of posts for this operation. The operation string will start with letter 'b', followed by two digit, the first digit can be '1' or '2' means the target should be all the posts with the same title or user id with the current post. The second digit can be '1' or '6', means deleting (the operation that the poster will lose one point experience) or killing (lose 2 points). The last character of the operation is 'y' or 'n', which means the beginning post that should be applied by this operation. 'y' means the first post in the list that satisfy the condition, while 'n' means the current post.

Input

The input consists of several test cases. In each test case, the first line is an integer N (0 < N < 2000) means the count of the posts, followed by N lines with one post in each. Each line has two strings, where the first one is user id and the second one is the title with the prefix. Note that the title with the prefix will always start at position 15. After the post list, there's another integer M indicates the operation count, followed by M lines. In each line, there will be either a user id or a number (the current post index, 1 based) with an operation (such as 'b11y'). Proceed until a case N = 0, which should not be processed.

Output

For each test case, there're M lines output. One line is corresponding to one operation in the input. For the line with a user id in, you should output the points of the experience of that user id (before all the operations, each user has 50 points of experience), otherwise, you should output the count of posts that will be deleted by this operation. If the user id doesn't exist, print "not exist". If the current post index given is too large that there aren't so many posts, output 0. Print a blank after each test case.

Sample Input

11
CorZ          O morning
mushroom      Re: morning
CorZ          O I am a fool
guanyao       Re: morning
Polivic       O agree with u
mushroom      Re: I am a fool
Polivic       Re: I am a fool
jqzhengcn     Re: I am a fool
jqzhengcn     Re: I am a fool
brightmornin  Re: agree with u
jqzhengcn     Re: agree with u
6
2 b11y
mushroom
10 b21y
6 b26n
jqzhengcn
morning
0

Sample Output

3
49
0
2
46
not exist

Explanation for the Sample

CorZ          O morning                 CorZ          O I am a fool                CorZ          O I am a fool
mushroom      Re: morning   -- b11y --> Polivic       O agree with u               Polivic       O agree with u
CorZ          O I am a fool             mushroom      Re: I am a fool              mushroom      Re: I am a fool
guanyao       Re: morning               Polivic       Re: I am a fool              Polivic       Re: I am a fool
Polivic       O agree with u            jqzhengcn     Re: I am a fool              jqzhengcn     Re: I am a fool
mushroom      Re: I am a fool           jqzhengcn     Re: I am a fool  -- b26n --> brightmornin  Re: agree with u
Polivic       Re: I am a fool           brightmornin  Re: agree with u
jqzhengcn     Re: I am a fool           jqzhengcn     Re: agree with u
jqzhengcn     Re: I am a fool
brightmornin  Re: agree with u
jqzhengcn     Re: agree with u

Submit    Status