// Arup Guha
// 4/3/2026
// What to do???

import java.util.*;

public class TaskManager {
	
	public static void main(String[] args) {
		
		// Read in number of tasks.
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		
		// Store tasks in here.
		Task[] list = new Task[n];
		
		// Read in the tasks.
		for (int i=0; i<n; i++) {
			long t = stdin.nextLong();
			String name = stdin.next();
			int priority = stdin.nextInt();
			long duration = stdin.nextLong();
			list[i] = new Task(name, t, priority, duration);
		}
		
		int curIdx = 0;
		long curTime = 0;
		
		// Safe to add first task.
		PriorityQueue<Task> pq = new PriorityQueue<Task>();
		
		// Load in all tasks that start at the time that the first one is requested.
		while (curIdx < n && list[curIdx].getRequestTime() == list[0].getRequestTime()) {
			pq.offer(list[curIdx]);
			curIdx++;
		}
		
		// Keep going until we complete the tasks.
		while (curIdx < n || pq.size() > 0) {
			
			// This is the next item I will work on.
			Task curTask = pq.poll();
			
			// Update current time. It's the later of these two things.
			curTime = Math.max(curTime, curTask.getRequestTime());
			
			// Do task. Print update.
			curTime += curTask.getDuration();
			System.out.println("Complete task "+curTask.getTaskName()+" at time t = "+curTime);
			
			// Add all tasks to the pq that were added while you were busy with the
			// current task.
			while (curIdx < n && list[curIdx].getRequestTime() <= curTime) {
				pq.offer(list[curIdx]);
				curIdx++;
			}
			
			// Important, if there's no current task, the way I have it, I still have
			// to load the pq.
			if (curIdx < n && pq.size() == 0) {
				
				// I need to store this somewhere,
				int baseIdx = curIdx;
				
				// Just like before, any time the queue is empty, we have to put ALL items
				// that start at the same time as the first item processed.
				while (curIdx < n && list[curIdx].getRequestTime() == list[baseIdx].getRequestTime()) {
					pq.offer(list[curIdx]);
					curIdx++;
				}			
				
			} // end if
		} // loop until all tasks finish.
	}
}

class Task implements Comparable<Task> {

	private String item;
	private long requestTime;
	private int priority;
	private long duration;
	
	// Just assign everything.
	public Task(String name, long startTime, int importance, long length) {
		item = name;
		requestTime = startTime;
		priority = importance;
		duration = length;
	}
	
	// The user will need access to these.
	
	public long getRequestTime() {
		return requestTime;
	}
	
	public String getTaskName() {
		return item;
	}
	
	public long getDuration() {
		return duration;
	}
	
	// For our PriorityQueue.
	public int compareTo(Task other) {
	
		// Most important.
		if (this.priority != other.priority)
			return this.priority - other.priority;
			
		// Secondary.
		if (this.duration != other.duration)
			return Long.compare(this.duration, other.duration);
			
		// Arbitrary.
		return item.compareTo(other.item);
	}
}