import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int m = sc.nextInt();
        Map<String, Integer> map1 = new LinkedHashMap<>();
        for (int i = 0; i < Math.max(0, m); i++) {
            String key = sc.next();
            int value = sc.nextInt();
            map1.put(key, value);
        }

        int n = sc.nextInt();
        Map<String, Integer> map2 = new LinkedHashMap<>();
        for (int i = 0; i < Math.max(0, n); i++) {
            String key = sc.next();
            int value = sc.nextInt();
            map2.put(key, value);
        }

        // Condition: if both sizes <= 0 → invalid input
        if (m <= 0 && n <= 0) {
            System.out.println("Invalid input");
            return;
        }

        // If both maps are identical
        if (map1.equals(map2)) {
            System.out.println("-1");
            return;
        }

        // Merge maps (second overrides first)
        Map<String, Integer> merged = new LinkedHashMap<>(map1);
        merged.putAll(map2);

        // Print merged map (in insertion order)
        for (Map.Entry<String, Integer> entry : merged.entrySet()) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
    }
}