import java.io.*;
import java.util.*;

public class ProductCatalog {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        // read first non-empty line for n
        String line = br.readLine();
        while (line != null && line.trim().isEmpty()) line = br.readLine();
        if (line == null) return;

        int n;
        try {
            n = Integer.parseInt(line.trim());
        } catch (NumberFormatException ex) {
            System.out.println("Invalid input");
            return;
        }

        // invalid if catalog empty or negative
        if (n <= 0) {
            System.out.println("Invalid input");
            return;
        }

        LinkedHashMap<String, Integer> catalog = new LinkedHashMap<>();
        int read = 0;
        while (read < n) {
            line = br.readLine();
            if (line == null) break;
            line = line.trim();
            if (line.isEmpty()) continue;

            // parse: last token is price, the rest (may contain spaces) is name
            int lastSpace = line.lastIndexOf(' ');
            if (lastSpace == -1) {
                // invalid product line (no price) — skip this line
                continue;
            }
            String name = line.substring(0, lastSpace).trim();
            String priceStr = line.substring(lastSpace + 1).trim();

            try {
                int price = Integer.parseInt(priceStr);
                catalog.put(name, price);
                read++;
            } catch (NumberFormatException ex) {
                // invalid price token — skip this product line
                continue;
            }
        }

        // read product-to-remove (first non-empty line)
        String removeProduct = null;
        while ((line = br.readLine()) != null) {
            if (!line.trim().isEmpty()) {
                removeProduct = line.trim();
                break;
            }
        }

        // If catalog ended up empty (shouldn't if n>0 and lines valid) — follow spec
        if (catalog.isEmpty()) {
            System.out.println("Invalid input");
            return;
        }

        if (removeProduct == null) {
            // nothing to remove — ambiguous, but print -1 (product not provided)
            System.out.println(-1);
            return;
        }

        if (!catalog.containsKey(removeProduct)) {
            System.out.println(-1);
            return;
        }

        // remove and print remaining
        catalog.remove(removeProduct);
        for (Map.Entry<String, Integer> e : catalog.entrySet()) {
            System.out.println(e.getKey() + " " + e.getValue());
        }
    }
}
