#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define MAXN 1000
#define ever (;;)
#define MIN(a,b) ((a) < (b) ? (a) : (b))

bool sell[MAXN];
int amount[MAXN];
int price[MAXN];

int besti(bool s, int n) {
	int i, ret = -1;
	for(i = 0; i <= n; i++)
		if(sell[i] == s && amount[i] > 0 && (ret == -1 || (s && price[ret] > price[i]) || (!s && price[ret] < price[i])))
			ret = i;
	return ret;
}

void testcase() {
	int i, n, selli, buyi, am, last = -1;
	char type[10];
	scanf("%d\n", &n);
	for(i = 0; i < n; i++) {
		scanf("%s %d shares at %d\n", type, &amount[i], &price[i]);
		sell[i] = (type[0] == 's');
		for ever {
			selli = besti(true, i);
			if(selli == -1) break;
			buyi = besti(false, i);
			if(buyi == -1) break;
			if(price[buyi] < price[selli]) break;
			am = MIN(amount[buyi], amount[selli]);
			amount[buyi] -= am;
			amount[selli] -= am;
			last = price[selli];
		}
		selli = besti(true, i);
		if(selli == -1) printf("- ");
		else printf("%d ", price[selli]);
		buyi = besti(false, i);
		if(buyi == -1) printf("- ");
		else printf("%d ", price[buyi]);
		if(last == -1) printf("-\n");
		else printf("%d\n", last);
	}
}

int main() {
	int t;
	scanf("%d\n", &t);
	while(t--) testcase();
	return 0;
}
