// Arup Guha
// 11/1/2026
// Solution main class for COP 3330 Fall 2026 Program 7C: In Demand Tickets with Priority

import java.util.*;

public class TicketSimulation {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int numOp = stdin.nextInt();
		
		// Where everyone will wait.
		PriorityQueue<Buyer> pq = new PriorityQueue<Buyer>();
		
		// Process operations.
		for (int loop=0; loop<numOp; loop++) {
		
			// Get next op.
			int op = stdin.nextInt();
			
			// Add to queue.
			if (op == 1) {
			
				// Read new buyer add to queue.
				String name = stdin.next();
				int priority = stdin.nextInt();
				int numTickets = stdin.nextInt();
				Buyer tmp = new Buyer(name, priority, numTickets);
				pq.offer(tmp);
			
			}
			
			// We have tickets!
			else {
			
				int numTickets = stdin.nextInt();
				
				// We keep on giving tickets until they run out.
				while (numTickets > 0) {
				
					// Get the next buyer.
					Buyer cur = pq.poll();
					
					// We have all of this buyer's tickets.
					if (cur.getNumTickets() <= numTickets) {
						System.out.println(cur+" receives "+cur.getNumTickets()+" tickets.");
						numTickets -= cur.getNumTickets();
					}
					
					// We're done and must go back to the queue.
					else {
						
						// Print out tickets received.
						System.out.println(cur+" receives "+numTickets+" tickets.");
						
						// Update object and number of tickets left.
						cur.giveTickets(numTickets);
						numTickets = 0;
						
						// Add this object back to the queue.
						pq.offer(cur);
						
					}
				}
				
			} // end if-else
		
		} // end for.
	}
}