// Arup Guha
// 1/7/2015
// Solution to 2005 MCPC Problem B: Overflowing Bookshelf

import java.util.*;

public class b {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int loop = 1;

		// Process all cases.
		while (n != -1) {

			// Create empty shelf.
			int[] books = new int[n];
			Arrays.fill(books, -1);

			String command = stdin.next();
			while (!command.equals("E")) {

				// Add
				if (command.equals("A")) {

					// Get book.
					int ID = stdin.nextInt();
					int width = stdin.nextInt();

					// Add this book to left end. Will always fit.
					int[] temp = new int[n];
					Arrays.fill(temp, -1);
					for (int i=0; i<width; i++)
						temp[i] = ID;

					// Set up variables.
					int i = 0, j = width, free =0;

					// Go through old shelf.
					for (i=0; i<n; i++) {

						// Run out of space on new shelf.
						if (j == n) break;

						// Got an old book to move.
						if (books[i] != -1)
							temp[j++] = books[i];

						// Count this free space.
						else if (free < width)
							free++;

						// We also move in the new shelf if we've passed all of our free spaces.
						else
							j++;
					}

					// We may have to delete a portion of the last book, if it didn't fully copy over.
					if (i < n && books[i] != -1) {
						int delID = books[i];
						j = n-1;
						while (temp[j] == delID)
							temp[j--] = -1;
					}

					// Copy back.
					for (i=0; i<n; i++)
						books[i] = temp[i];
				}

				// Remove
				else {

					// Find this ID and get rid of it.
					int ID = stdin.nextInt();
					for (int i=0; i<n; i++)
						if (books[i] == ID)
							books[i] = -1;
				}

				// Get next command.
				command = stdin.next();
			}

			// Print result.
			System.out.print("PROBLEM "+loop+":");

			// Find each unique book and print.
			for (int i=0; i<n; i++)
				if (books[i] != -1 && (i == 0 || books[i-1] != books[i]))
					System.out.print(" "+books[i]);
			System.out.println();

			// Get next case.
			n = stdin.nextInt();
			loop++;
		}
	}
}