import java.util.Scanner;

class solution {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 0; t < T; ++t) {
			int N = sc.nextInt();
			String[] B = new String[N];
			int posB = 0, endB = 0;
			String[] ans = new String[0];

			int n5 = 0; // Number of 5 dollar notes teacher has
			for (int i = 0; i < N; ++i) {
				while (n5 > 0 && posB < endB) {
					posB++;
					n5--;
				}
				String name = sc.next();
				int amt = sc.nextInt();
				if (amt == 15) n5++;
				else if (n5 > 0) n5--;
				else {
					B[endB] = name;
					endB++;
				}
				if (endB - posB > ans.length) {
					ans = new String[endB-posB];
					for (int j = 0; j < endB-posB; ++j)
						ans[j] = B[posB+j];
				}
			}
			if (ans.length == 0) System.out.println("Line B stayed empty.");
			else {
				for (int i = 0; i < ans.length; ++i) {
					if (i > 0) System.out.print(" ");
					System.out.print(ans[i]);
				}
				System.out.println();
			}
		}
	}
}
