// NWERC'10 solution for problem 'stockprices'
// Jaap Eldering

#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

int main()
{
	int run, nruns;

	cin >> nruns;

	for(run=1; run<=nruns; run++) {
		int N;
		cin >> N;

		map<int,int> sel, buy;
		int buyp = -1, selp = -1, stockp = -1;

		for(int i=0; i<N; i++) {

		string type, shares, at;
		int n, p;

		cin >> type >> n >> shares >> at >> p;

		if ( type=="buy" ) {
			buy[p] += n;
		} else {
			sel[p] += n;
		}

		buyp = ( buy.size()>0 ? buy.rbegin()->first : -1 );
		selp = ( sel.size()>0 ? sel.begin()->first  : -1 );

		while ( buyp!=-1 && selp!=-1 && buyp>=selp ) {

			stockp = selp;
			int n = min(buy.rbegin()->second,sel.begin()->second);
			buy[buyp] -= n;
			sel[selp] -= n;
			if ( buy[buyp]==0 ) buy.erase(buyp);
			if ( sel[selp]==0 ) sel.erase(selp);

			buyp = ( buy.size()>0 ? buy.rbegin()->first : -1 );
			selp = ( sel.size()>0 ? sel.begin()->first  : -1 );
		}

		if ( selp<0 ) cout << "- "; else cout << selp << ' ';
		if ( buyp<0 ) cout << "- "; else cout << buyp << ' ';
		if ( stockp<0 ) cout << "-"; else cout << stockp;
		cout << endl;

		}
	}

	return 0;
}
