// Author: Adrian Kuegel
// Date: September 6th, 2010
// Algorithm: Simulation
// Complexity: O(n * m) - n number of orders, m maximum value of order

import java.util.*;

public class adrian {
	public static void main(String [] args) throws Exception {
		Scanner in = new Scanner(System.in);
		int tc = in.nextInt();
		while(tc-- > 0) {
			int n = in.nextInt();
			int [] buy = new int[1001];
			int [] sell = new int[1001];
			int last_deal = -1;
			while(n-- > 0) {
				String order_type = in.next();
				int x = in.nextInt();
				in.next();
				in.next();
				int y = in.nextInt();
				if (order_type.equals("buy"))
					buy[y] += x;
				else
					sell[y] += x;
				int s, b = 1000;
				while(b > 0 && buy[b] == 0)
					--b;
				for (s=1; s<1001; ++s) {
					while(sell[s] > 0) {
						if (b >= s) {
							last_deal = s;
							if (buy[b] >= sell[s]) {
								buy[b] -= sell[s];
								sell[s] = 0;
							}
							else {
								sell[s] -= buy[b];
								buy[b] = 0;
							}
							while(b > 0 && buy[b] == 0)
								--b;
						}
						else
							break;
					}
					if (sell[s] > 0)
						break;
				}
				System.out.println((s<1001?s:"-")+" "+(b>0?b:"-")+" "+(last_deal<0?"-":last_deal));
			}
		}
	}
}
