DVDs

No attempts yetTime limit1sMemory limit128 MB

Problem

A local company, "DVDs R Us", needs your help with a stock-management system. They sell DVDs online from a local warehouse and need to know, at any moment, how many DVDs of each title they have in stock.

Each DVD title has a stock code and is allocated a certain amount of storage space in the warehouse. The more popular a title is, the more space it is allocated. DVDs are continually being sold and replaced, so the company needs a system that tracks how many of each title remain in stock.

Given the starting stock for several titles and a list of sale and restock transactions for each, report the final number of DVDs in stock for every title.

Input

The input describes several DVD titles. The data for one title is given as follows:

  • The first line is the stock code: a 7-character code made up of uppercase letters and digits only.
  • The second line contains two integers $M$ and $S$ separated by a space. $M$ is the maximum number of DVDs of that title that can be held in stock at any one time ($20 \le M \le 500$), and $S$ is the number currently in stock ($0 \le S \le M$).
  • The third line contains a single integer $T$, the number of transactions that follow ($0 < T \le 100$).
  • Each of the next $T$ lines describes one transaction: an uppercase letter (S or R), a space, and a positive integer less than $1000$.
    • S is a sale: the number tells how many DVDs were sold. If the sale is for more than the current stock, only the DVDs currently in stock are sold (the stock cannot go below $0$).
    • R is a restock: the number tells how many DVDs are added. If this would raise the stock above the maximum $M$, the extra items are sent back (the stock cannot exceed $M$).

The input ends with a line containing a single # in place of a stock code; do not process this title.

Output

For each DVD title, print its stock code, a single space, and the number of DVDs in stock after all of its transactions have been applied.