// Arup Guha
// 10/31/2013 (finished)
// Solution to 2008 MCPC Problem F: Serial Numbers

import java.util.*;

public class f {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		String name = stdin.nextLine();

		// Go through each case.
		while (!name.equals("END")) {

			// Echo name.
			System.out.println(name);

			// Start our list.
			ArrayList<interval> list = new ArrayList<interval>();
			String line = stdin.nextLine();

			// Read in each update.
			while (!line.equals("0")) {

				// Parse out this interval.
				StringTokenizer tok = new StringTokenizer(line);
				int low = Integer.parseInt(tok.nextToken());
				int high = Integer.parseInt(tok.nextToken());
				char c = tok.nextToken().charAt(0);
				int val = Integer.parseInt(tok.nextToken());
				interval cur = new interval(low, high, c, val);

				// Update based on this interval.
				merge(list, cur);

				line = stdin.nextLine();
			}

			// Print the list.
			for (int i=0; i<list.size(); i++)
				System.out.println(list.get(i));

			// Go to the next case.
			name = stdin.nextLine();
		}
	}

	public static void merge(ArrayList<interval> list, interval cur) {

		// Add before.
		if (list.size() == 0 || cur.end < list.get(0).start) {
			list.add(0, cur);
			slim(list, 0);
			return;
		}

		// Add at end.
		if (cur.start > list.get(list.size()-1).end) {
			list.add(cur);
			slim(list, list.size()-1);
			return;
		}

		// Return 2*i if item contained in range i, return 2*i-1 if below, 2*i+1 if above.
		int lowI = binSearch(list, cur.start);
		int highI = binSearch(list, cur.end);

		// Check special cases to update the index to which we'll insert.
		if (lowI%2 == 1) lowI++;
		if (lowI%2 == 0 && cur.start > list.get(lowI/2).start) lowI+=2;
		int i = lowI/2;

		// Add this item.
		list.add(i, cur);

		// Clip previous item range, and add extra range, if necessary.
		if (i>0 && list.get(i-1).end >= list.get(i).start) {
			int oldend = list.get(i-1).end;
			list.get(i-1).end = cur.start-1;
			if (oldend > cur.end)
				list.add(i+1, new interval(cur.end+1, oldend, list.get(i-1).status, list.get(i-1).transfer));
		}

		// Remove redundant items.
		while (i < list.size()-1 && list.get(i+1).end <= cur.end)
			list.remove(i+1);

		// Clip subsequence item rage, if necessary.
		if (i<list.size()-1 && list.get(i+1).start <= cur.end)
			list.get(i+1).start = cur.end+1;

		// Just in case...
		slim(list, i);
	}

	// Checks to see if adjacent items to item i are the same item, and iteratively usurps them into
	// one item.
	public static void slim(ArrayList<interval> list, int i) {

		// Merge with equivalent adjacent units.
		while (i > 0 && list.get(i).sameItem(list.get(i-1)) && list.get(i-1).end == list.get(i).start-1) {
			list.get(i-1).end = list.get(i).end;
			list.remove(i);
			i--;
		}

		// Merge with equivalent adjacent units.
		while (i < list.size()-1 && list.get(i).sameItem(list.get(i+1)) && list.get(i).end == list.get(i+1).start-1) {
			list.get(i).end = list.get(i+1).end;
			list.remove(i+1);
		}
	}

	// Returns 2i if x belongs to the range of list.get(i), and 2i+1 if x is in the range directly above
	// that stored in list.get(i).
	public static int binSearch(ArrayList<interval> list, int x) {

		// Outliers.
		if (x < list.get(0).start) return -1;
		if (x > list.get(list.size()-1).end) return 2*list.size()-1;

		// Typical binary search.
		int low = 0, high = list.size()-1;
		while (low <= high) {

			int mid = (low+high)/2;

			// Got it!
			if (list.get(mid).in(x)) return 2*mid;

			// Go lower.
			else if (x < list.get(mid).start) high = mid-1;

			// Go higher.
			else low = mid+1;
		}

		// low and high crossed over, so we're in between ranges.
		return 2*high + 1;
	}
}

class interval {

	public int start;
	public int end;
	public char status;
	public int transfer;

	public interval(int s, int e, char stat, int tran) {
		start = s;
		end = e;
		status = stat;
		transfer = tran;
	}

	// Returns true iff this interval contains x.
	public boolean in(int x) {
		return x >= start && x <= end;
	}

	// Returns true iff other and this are essentially the same object.
	public boolean sameItem(interval other) {
		return this.status == other.status && this.transfer == other.transfer;
	}

	// For our output.
	public String toString() {
		return start + " " + end + " " + status + " " + transfer;
	}
}