import java.util.*;

public class StockTracker {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // Read N and K
        if (!sc.hasNextInt()) {
            System.out.println("Invalid input");
            return;
        }
        int N = sc.nextInt();
        int K = sc.nextInt();

        if (N < 1 || N > 1000 || K < 1 || K > N) {
            System.out.println("Invalid input");
            return;
        }

        // Store initial prices
        Map<Integer, Integer> initial = new HashMap<>();
        Map<Integer, Integer> current = new HashMap<>();

        for (int i = 0; i < N; i++) {
            if (!sc.hasNextInt()) {
                System.out.println("Invalid input");
                return;
            }
            int stockId = sc.nextInt();
            if (!sc.hasNextInt()) {
                System.out.println("Invalid input");
                return;
            }
            int initialPrice = sc.nextInt();

            if (initialPrice < 0 || initialPrice > 100000) {
                System.out.println("Invalid input");
                return;
            }

            initial.put(stockId, initialPrice);
            current.put(stockId, initialPrice);
        }

        // Read number of updates
        if (!sc.hasNextInt()) {
            System.out.println("Invalid input");
            return;
        }
        int U = sc.nextInt();

        for (int i = 0; i < U; i++) {
            if (!sc.hasNextInt()) {
                System.out.println("Invalid input");
                return;
            }
            int stockId = sc.nextInt();
            if (!sc.hasNextInt()) {
                System.out.println("Invalid input");
                return;
            }
            int newPrice = sc.nextInt();

            if (!initial.containsKey(stockId) || newPrice < 0 || newPrice > 100000) {
                System.out.println("Invalid input");
                return;
            }

            // Update price
            current.put(stockId, newPrice);

            // Recalculate top K
            List<int[]> diffs = new ArrayList<>();
            for (int id : current.keySet()) {
                int diff = Math.abs(current.get(id) - initial.get(id)); // <- using Math.abs
                diffs.add(new int[]{id, diff});
            }

            // Sort by absolute difference descending, then by stockId ascending
            diffs.sort((a, b) -> {
                if (b[1] == a[1]) return Integer.compare(a[0], b[0]);
                return Integer.compare(b[1], a[1]);
            });

            // Print top K stock IDs
            for (int j = 0; j < K; j++) {
                System.out.print(diffs.get(j)[0]);
                if (j < K - 1) System.out.print(" ");
            }
            System.out.println();
        }

        sc.close();
    }
}