Time limit
2s
Memory limit
128 MB
A search engine wants to rank websites so that, among matching results, websites with higher trust scores appear first.
Initially every website has score 1. If website A has a link to website B, then A's score is added to B's score only when B cannot reach A by following links directly or indirectly. If B can reach A, that link is ignored for scoring, because otherwise cycles could increase scores without bound.
Given the link information and the name of one website, compute that website's score.
The first line contains the number of link-information lines N. N is a positive integer not greater than 50.
Each of the next N lines has the form X K Y1 Y2 ... YK. X is a website name, and K is the number of websites that point to X. Each Yi has a link to X.
The last line contains the name of the website whose score must be computed.
Every website name consists only of uppercase English letters and has length at most 50. Each K is a nonnegative integer not greater than 24. The incoming-link information for the same website does not appear more than once. The website to query always appears in the link information.
Print the answer on the first line.