1.

package acm_10199_tourist_guide;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * FWP, AusgewŠhlte Probleme aus dem ACM Programming Contest, SS10
 * Problem: acm_10199_tourist_guide
 * Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=38&page=show_problem&problem=1140
 *
 * @author Martin Lambeck
 * @version 1.0, 14.08.2010
 *
 * Method : bfs, connectivity
 * Status : Accepted
 * Runtime: 0.884
 */


public class Main
{
    static Scanner sc = new Scanner(System.in);
    static int tcase = 0;
    static HashMap<String, Zone> zones = new HashMap<String, Zone>(101);
    static LinkedList<Zone> cams = new LinkedList<Zone>();
    static ArrayList<Integer> groups = new ArrayList<Integer>(101);
   
    public static void main(String... args)
    {
        while (testcase())
            ;
    }

    public static boolean testcase()
    {
        zones.clear();
        cams.clear();
        groups.clear();
       
        int n = sc.nextInt();

        if (n == 0)
            return false;

        for (int i = 0; i < n; i++)
        {
            String name = sc.next();
            zones.put(name, new Zone(name));
        }

        int r = sc.nextInt();

        for (int i = 0; i < r; i++)
        {
            Zone z1 = zones.get(sc.next());
            Zone z2 = zones.get(sc.next());

            z1.neighbors.add(z2);
            z2.neighbors.add(z1);
        }

       
        fillGroups(); //find number of nodes in each component of the graph.

        for (Zone black : zones.values())
        {
            if (groups.get(black.group) < 3) //component with nodes < 3, no cam possible
                continue;
           
            for (Zone z : zones.values())  //prepare for bfs
            {
                z.visited = false;
            }
           
            //see description of reachable()
            if (reachable(black) < (groups.get(black.group) - 1))
                cams.add(black);
        }

        tcase++;

        if (tcase > 1)
            System.out.println();

        System.out.printf("City map #%d: %d camera(s) found%n", tcase, cams.size());

        Collections.sort(cams);

        for (Zone cam : cams)
            System.out.println(cam.name);


        return true;
    }

    //returns the number of nodes, which are reachable from any node that is in the same graph as the blacklisted node
    // assume c = component, which contains black (must have at least 3 nodes, fails otherwise)
    // g = c with black and all edges from/to black removed
    // v = any node in g
    // ng = number of reachable nodes (in g) starting at v
    // nc = number of nodes in c
    // if, and only if (ng+1 < nc) then black disconnects the graph
    static int reachable(Zone black)
    {
        int found = 1;
        LinkedList<Zone> q = new LinkedList<Zone>();

        //find ANY node, which is in the same component (group) as the blacklisted node, but not the black node itself
        //serves as start for bfs
        Zone z = black.neighbors.getFirst(); //will not point to itself, see input description
       
        z.visited = true;
        q.add(z);
       


        //bfs
        //finds the number of reachable nodes
        while (q.size() > 0)
        {
            z = q.pollFirst();

            for (Zone t : z.neighbors)
            {
                if (!t.visited && (t != black))
                {
                    t.visited = true;
                    q.add(t);
                    found++;
                }
            }
        }


        return found;
    }

    //find all connected components of the graph.
    //fill the groups array with the number of nodes of each component
    static void fillGroups()
    {
        int group = -1;
        int groupsize = -1;
        HashMap<String, Zone> unvisited = new HashMap<String, Zone>(zones); //clone
        LinkedList<Zone> q = new LinkedList<Zone>();
       
        while (unvisited.size() > 0)
        {
            group++;
            groupsize = 1;
           
            Zone start = unvisited.values().iterator().next(); //yet unvisited node
           
            start.group = group; //set group id
            unvisited.remove(start.name); //visited
           
            q.add(start);
           
           
            //do bfs, to find all reachable nodes
            while (q.size() > 0)
            {
                Zone z = q.pollFirst();
               
                for (Zone nb : z.neighbors) //for each neighbor
                {
                    if (nb.group < 0) //unvisited
                    {
                        unvisited.remove(nb.name);     //visited
                        nb.group = group;             //set group id
                        q.add(nb);                     //queue for bfs
                        groupsize++;
                    }
                }
            }
           
            groups.add(groupsize); //insert number of nodes
        }
    }
}

class Zone implements Comparable<Zone>
{
    LinkedList<Zone> neighbors = new LinkedList<Zone>();
    String name;
    boolean visited = false; //used in bfs
    int group = -1;

    public Zone(String n)
    {
        name = n;
    }

    //alphabetic compare of names
    public int compareTo (Zone other)
    {
        return name.compareTo(other.name);
    }
}