// Arup Guha
// 4/8/2026
// Solution to Program 8B: What Task?

import java.util.*;

public class whattask {

	public static void main(String[] args) {
	
		// Get # of commands.
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		
		// Set up the priority queue.
		PriorityQueue<Task> pq = new PriorityQueue<Task>();
		
		// Process the commands.
		for (int i=0; i<n; i++) {
		
			// First get command type.
			int cmd = stdin.nextInt();
			
			// Oof! More work!
			if (cmd == 1) {
			
				// Get the info and add to the priority queue.
				String item = stdin.next();
				int money = stdin.nextInt();
				pq.offer(new Task(item, money));
			}
			
			// Time to actually do some work!
			else {
				System.out.println(pq.poll());
			}
		}
	}
}

// Task class to manage tasks.
class Task implements Comparable<Task> {

	private String item;
	private int money;
	
	public Task(String name, int cash) {
		item = name;
		money = cash;
	}
	
	public int compareTo(Task other) {
		
		// Only if the money is different.
		if (this.money != other.money)
			return other.money - this.money;
		
		// Here we use names.
		return item.compareTo(other.item);
	}
	
	public String toString() {
		return item+" "+money;
	}
}
