import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine(); // Consume leftover newline

        if (n <= 0) {
            System.out.println("Invalid input.");
            return;
        }

        Map<String, Integer> map = new HashMap<>();
        List<Integer> values = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            String[] parts = sc.nextLine().split(" ");
            String key = parts[0];
            int value = Integer.parseInt(parts[1]);

            map.put(key, value);
            values.add(value);
        }

        // Check if all values are the same
        boolean allSame = true;
        for (int i = 1; i < values.size(); i++) {
            if (!values.get(i).equals(values.get(0))) {
                allSame = false;
                break;
            }
        }

        if (allSame) {
            System.out.println("-1");
            return;
        }

        // Sort by value descending
        map.entrySet().stream()
            .sorted((a, b) -> b.getValue().compareTo(a.getValue()))
            .forEach(entry -> System.out.println(entry.getKey() + " " + entry.getValue()));
    }
}
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine(); // Consume leftover newline

        if (n <= 0) {
            System.out.println("Invalid input.");
            return;
        }

        Map<String, Integer> map = new HashMap<>();
        List<Integer> values = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            String[] parts = sc.nextLine().split(" ");
            String key = parts[0];
            int value = Integer.parseInt(parts[1]);

            map.put(key, value);
            values.add(value);
        }

        // Check if all values are the same
        boolean allSame = true;
        for (int i = 1; i < values.size(); i++) {
            if (!values.get(i).equals(values.get(0))) {
                allSame = false;
                break;
            }
        }

        if (allSame) {
            System.out.println("-1");
            return;
        }

        // Sort by value descending
        map.entrySet().stream()
            .sorted((a, b) -> b.getValue().compareTo(a.getValue()))
            .forEach(entry -> System.out.println(entry.getKey() + " " + entry.getValue()));
    }
}
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine(); // Consume leftover newline

        if (n <= 0) {
            System.out.println("Invalid input.");
            return;
        }

        Map<String, Integer> map = new HashMap<>();
        List<Integer> values = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            String[] parts = sc.nextLine().split(" ");
            String key = parts[0];
            int value = Integer.parseInt(parts[1]);

            map.put(key, value);
            values.add(value);
        }

        // Check if all values are the same
        boolean allSame = true;
        for (int i = 1; i < values.size(); i++) {
            if (!values.get(i).equals(values.get(0))) {
                allSame = false;
                break;
            }
        }

        if (allSame) {
            System.out.println("-1");
            return;
        }

        // Sort by value descending
        map.entrySet().stream()
            .sorted((a, b) -> b.getValue().compareTo(a.getValue()))
            .forEach(entry -> System.out.println(entry.getKey() + " " + entry.getValue()));
    }
}
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine(); // Consume leftover newline

        if (n <= 0) {
            System.out.println("Invalid input.");
            return;
        }

        Map<String, Integer> map = new HashMap<>();
        List<Integer> values = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            String[] parts = sc.nextLine().split(" ");
            String key = parts[0];
            int value = Integer.parseInt(parts[1]);

            map.put(key, value);
            values.add(value);
        }

        // Check if all values are the same
        boolean allSame = true;
        for (int i = 1; i < values.size(); i++) {
            if (!values.get(i).equals(values.get(0))) {
                allSame = false;
                break;
            }
        }

        if (allSame) {
            System.out.println("-1");
            return;
        }

        // Sort by value descending
        map.entrySet().stream()
            .sorted((a, b) -> b.getValue().compareTo(a.getValue()))
            .forEach(entry -> System.out.println(entry.getKey() + " " + entry.getValue()));
    }
}
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine(); // Consume leftover newline

        if (n <= 0) {
            System.out.println("Invalid input.");
            return;
        }

        Map<String, Integer> map = new HashMap<>();
        List<Integer> values = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            String[] parts = sc.nextLine().split(" ");
            String key = parts[0];
            int value = Integer.parseInt(parts[1]);

            map.put(key, value);
            values.add(value);
        }

        // Check if all values are the same
        boolean allSame = true;
        for (int i = 1; i < values.size(); i++) {
            if (!values.get(i).equals(values.get(0))) {
                allSame = false;
                break;
            }
        }

        if (allSame) {
            System.out.println("-1");
            return;
        }

        // Sort by value descending
        map.entrySet().stream()
            .sorted((a, b) -> b.getValue().compareTo(a.getValue()))
            .forEach(entry -> System.out.println(entry.getKey() + " " + entry.getValue()));
    }
}
