import java.util.*;
import java.io.*;

import static java.lang.System.*;

public class Stamps {
    public static void main(String[] args) throws IOException {
        Scanner input = new Scanner(new File("stamps.dat"));
        int times = input.nextInt();

        while (times-->0) {
             // This problem can easily be solved with sets. A set
             // is a sorted collection of elements with no two elements
             // being considered equal.


            TreeSet<String> wishlist = new TreeSet<>();
            int listSize = input.nextInt();
            input.nextLine();

            while (listSize-->0) {
                wishlist.add(input.nextLine()); // fills the wishlist
            }
            TreeSet<String> collectedStamps = new TreeSet<>();
            int numStamps = input.nextInt();
            input.nextLine();

            while (numStamps-->0) {
                collectedStamps.add(input.nextLine());
                // Since we are adding to a set, duplicate stamps are removed
            }
            wishlist.removeAll(collectedStamps); // The wishlist now contains only stamps we don't have
            // remove all the elements of collectedStamps from wishlist

            out.println("Stamps collected: " + collectedStamps.size());
            out.println("Stamps missing:");

            if (wishlist.isEmpty()) {
                out.println("None");
            } else {
                for (String stamp : wishlist) { // Remember that sets are sorted...
                    // ... so this iterates and prints in alphabetical order!
                    out.println(stamp);
                }
            }
            out.println();
        }
    }
}

results matching ""

    No results matching ""