Under construction

Still being built. Things may change

Reality

Time limit2sMemory limit512 MB

Summary
Choose which contestants to eliminate so that the number of jurors whose two wishes both come true is as large as possible.
Level

Medium7 of 10

Topics
Graph
Solved
No attempts yet

Problem

Život na kavi is a popular reality show in which members of parliament compete. The contestants are split into a red team and a black team, and each week a set number of contestants is eliminated from the show.

The jury decides who leaves. Each jury member writes on a separate sheet of paper the name of exactly one contestant who should stay in the show, and the name of exactly one contestant who should leave. The jurors are corrupt, so the two names on the same sheet never belong to members of the same team.

A jury member is happy if both of their wishes come true: the contestant they wanted to stay is still in the show at the end of the week, and the contestant they wanted eliminated is eliminated. Choose the set of contestants to eliminate so that the number of happy jury members is as large as possible.

Input

The first line contains a natural number nn (1≤n≤2501 \le n \le 250), the number of members of the red team. The next nn lines each contain the name of one red team member.

The next line contains a natural number mm (1≤m≤2501 \le m \le 250), the number of members of the black team. The next mm lines each contain the name of one black team member.

The next line contains a natural number kk (1≤k≤10001 \le k \le 1000), the number of jury members. The next kk lines each contain two names separated by a space. The first name is the contestant the jury member wants to stay, and the second is the contestant they want to leave.

All names are distinct and consist of at most 10 lowercase English letters.

Output

On the first line, print the number xx of contestants who leave the show. On each of the next xx lines, print the name of one leaving contestant, in any order.

Examples2

  1. Example 1

    Input
    2
    ankica
    brankica
    1
    mirko
    3
    ankica mirko
    brankica mirko
    mirko brankica
    
    Expected output
    1
    mirko
    
  2. Example 2

    Input
    3
    ante
    branko
    simic
    3
    ivan
    goran
    kovacic
    5
    ante kovacic
    goran ante
    kovacic simic
    branko kovacic
    simic goran
    
    Expected output
    2
    goran
    kovacic