Time limit: 0.5 seconds Memory limit: 256 MB Uncle, who is a very money-loving person,…
- User
Time limit: 0.5 seconds Memory limit: 256 MB Uncle, who is a very money-loving person, has turned to multilateral espionage.
uncle in n It is a member of n different spy agencies. Each organization pays the uncle by receiving secret information about another organization. Uncle cannot sell the same information to two spy agencies, otherwise the information will be worthless.
in each of q q Yesterday, an e-mail containing confidential information from an unknown person was received by uncle. If the uncle sells information to two different organizations two days in a row, he has to go from the first organization to the second organization. We know that Amo sold this information in such a way that he has the least number of transfers between organizations. Knowing which spy agency each of the e-mails is related to, say what is the least number of times the uncle moves between spy agencies.
input The first line of the input contains the number n n represents the number of uncle's spy agencies. Then in each of n The next line contains the name of one of these organizations. The name of each organization is different from another. Each name can contain several words, each consisting of lower or upper case English letters and numbers.
The next line of input contains the number q q represents the number of emails received by the uncle. in i The i-th line of q q The next line is the name of the organization that has email information i I am related to it.
2 ≤ n ≤ 100 2≤n≤100 0 ≤ q ≤ 1000 0≤q≤1000
output On the only output line, print a number equal to the least number of times the uncle moved between spy agencies.
Example Sample entry 1 3 KGB Central Intelligence Agency Central Intelligence Agency 2 6 KGB Central Intelligence Agency Central Intelligence Agency Central Intelligence Agency 2 Central Intelligence Agency 2 KGB Plain text Sample output 1 1 Plain text Uncle can sell the information of the first 3 days to the Central Intelligence Agency 2 and then go to the Central Intelligence Agency and give them the information of the next 3 days. write code in c++
- Assistant