NWERC10H - Stock Prices

In this problem we deal with the calculation of stock prices. You need to know the following things about stock prices:

  • The ask price is the lowest price at which someone is willing to sell a share of a stock.
  • The bid price is the highest price at which someone is willing to buy a share of a stock.
  • The stock price is the price at which the last deal was established.

Whenever the bid price is greater than or equal to the ask price, a deal is established. A buy order offering the bid price is matched with a sell order demanding the ask price, and shares are exchanged at the rate of the ask price until either the sell order or the buy order (or both) is fulfilled (i.e., the buyer wants no more stocks, or the seller wants to sell no more stocks). You will be given a list of orders (either buy or sell) and you have to calculate, after each order, the current ask price, bid price and stock price.

Input

On the first line a positive integer: the number of test cases, at most 100. After that per test case:

  • One line with an integer n (1 ≤ n ≤ 1 000): the number of orders.
  • n lines of the form "order_type x shares at y", where order_type is either "buy" or "sell", x (1 ≤ x ≤ 1 000) is the number of shares of a stock someone wishes to buy or to sell, and y (1 ≤ y ≤ 1 000) is the desired price.

Output

Per test case:

  • n lines, each of the form "ai bi si", where ai, bi and si are the current ask, bid and stock prices, respectively, after the i-th order has been processed and all possible deals have taken place. Whenever a price is not defined, output "-" instead of the price.

Example

Input:
2
6
buy 10 shares at 100
sell 1 shares at 120
sell 20 shares at 110
buy 30 shares at 110
sell 10 shares at 99
buy 1 shares at 120
6
sell 10 shares at 100
buy 1 shares at 80
buy 20 shares at 90
sell 30 shares at 90
buy 10 shares at 101
sell 1 shares at 80

Output:
- 100 -
120 100 -
110 100 -
120 110 110
120 100 99
- 100 120
100 - -
100 80 -
100 90 -
90 80 90
100 80 90
100 - 80

Added by:Diego Satoba
Date:2011-03-23
Time limit:2.192s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:NWERC 2010 Contest

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.