/* NWERC 2010: Sample solution to "Stock Prices"
 * Author: Sean Lip
 *
 * Algorithm: simulation
 */

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
	
	int T;
	cin >> T;
	for(int tes = 0; tes < T; tes++)
	{
	
	int N;
	cin >> N;
	
	string instr;
	int numShares, pr;
	string ignore;
	
	int buy[1010];
	int sell[1010];
	
	for(int i = 0; i < 1001; i++)
		buy[i] = 0, sell[i] = 0;
	
	int last = -1;

	for(int i = 0; i < N; i++)
	{		
		cin >> instr >> numShares >> ignore >> ignore >> pr;
		if(instr == "buy") buy[pr] += numShares;
		else if(instr == "sell") sell[pr] += numShares;
		else
		{
			cout << "ERROR: bad instruction\n";
			return 1;
		}
				
		if(pr < 1 || pr > 1000 || numShares < 1 || numShares > 1000)
		{
			cout << "ERROR: input limits not obeyed; price = " << pr << " and number of shares = " << numShares << endl;
			return 1;
		}
		
		int highestBuy = -1;
		int lowestSell = 1001;
		for(int i = 1000; i >= 0; i--)
			if(buy[i] > 0)
			{
				highestBuy = i;
				break;
			}
		for(int i = 0; i < 1001; i++)
			if(sell[i] > 0)
			{
				lowestSell = i;
				break;
			}
		
		while(highestBuy >= lowestSell)
		{
			int trade = min(buy[highestBuy], sell[lowestSell]);
			if(trade > 0)
				buy[highestBuy] -= trade, sell[lowestSell] -= trade, last = lowestSell;
			while(highestBuy >= 0 && buy[highestBuy] == 0)
				highestBuy--;
			while(lowestSell < 1001 && sell[lowestSell] == 0)
				lowestSell++;
		}
		
		if(lowestSell == 1001) cout << "-";
		else cout << lowestSell;
		cout << " ";
			
		if(highestBuy == -1) cout << "-";
		else cout << highestBuy;
		cout << " ";
		
		if(last == -1) cout << "-";
		else cout << last;
		cout << endl;
	}
	}
	return 0;
}