Wikipedia
Petya, inspired by the success of "Wikipedia," has decided to create a similar encyclopedia on his homepage. As he is learning English, he opted to make the encyclopedia in English.
To begin, Petya transcribed several texts from the "Encyclopedia Britannica." Now, he wants to insert links to other articles within these texts. Given the large number of articles, he decided to automate this process.
In a wiki page, a link to an article is formatted as:
[[Article Title|link text]]
For example, in the sentence In the wild cats are often enemies of [[Dog|dogs]]
, the word "dogs" is a link to the article "Dog". If the article title is the same as the link text, the link can be formatted simply as:
[[Article Title]]
For instance, in the sentence Growing together a [[dog]] and a cat can often be friends
, the word "dog" links to the article "dog". Here, the case of the first letter in article titles is ignored, but the case of other letters is significant. Therefore, the word "dog" can link to the article "Dog", but "DOG" cannot.
Your task is to help Petya insert links on his site. The site consists of a set of articles, each with a title—a single word—and a text. For each title word, all its word forms and synonyms are known.
A word in the text is defined as a sequence of English alphabet letters, bounded by non-letter characters or the start or end of a line. In the article text, you need to find all words that are word forms or synonyms of the titles of other articles and convert them into wiki links.
Input Data
The first line of the input file contains the number n
— the number of articles in Petya's Wikipedia (2 ≤ n ≤ 50
). Then follow the descriptions of the articles.
Each article description begins with a line containing the article's title. The next line contains a number k
— the number of word forms and synonyms for the article title, which does not exceed 10. The following k
lines each contain one word — word forms and synonyms for the current article title. Then there is a line with the number l
— the number of lines in the article text, which does not exceed 10. This is followed by the article text — l
lines, each no longer than 80 characters.
All article titles are unique. All word forms and synonyms of all titles are distinct and different from the article titles.
All words consist of Latin alphabet letters, with each word in the input file not exceeding 20 characters. The input file contains only spaces, line breaks, and characters with ASCII codes from 32 to 126.
Output Data
Output the articles with links inserted. Present the articles as follows: first, output the article title. Then, output the article text, maintaining the line breaks as in the input file. Convert all words in the text that match the article title, or a word form or synonym of a different article title, into links. When comparing words, ignore the case of the first letter, but respect the case of the others. Words that match the title should be converted into the short version of the link, while those that do not match should be converted into the full version.