eolymp
bolt
Try our new interface for solving problems
Problems

Censoring (Gold)

Censoring (Gold)

Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so they have plenty of material to read while waiting around in the barn during milking sessions. Unfortunately, the latest issue contains a rather inappropriate article on how to cook the perfect steak, which FJ would rather his cows not see (clearly, the magazine is in need of better editorial oversight).

FJ has taken all of the text from the magazine to create the string s of length at most 105 characters. He has a list of censored words t1 ... tn that he wishes to delete from s. To do so Farmer John finds the earliest occurrence of a censored word in s (having the earliest start index) and removes that instance of the word from s. He then repeats the process again, deleting the earliest occurrence of a censored word from s, repeating until there are no more occurrences of censored words in s. Note that the deletion of one censored word might create a new occurrence of a censored word that didn't exist before.

Farmer John notes that the censored words have the property that no censored word appears as a substring of another censored word. In particular this means the censored word with earliest index in s is uniquely defined.

Please help FJ determine the final contents of s after censoring is complete.

Input

The first line will contain s. The second line will contain n, the number of censored words. The next n lines contain the strings t1 ... tn. Each string will contain lower-case alphabet characters (in the range a..z), and the combined lengths of all these strings will be at most 105.

Output

The string s after all deletions are complete. It is guaranteed that s will not become empty during the deletion process.

Time limit 1 second
Memory limit 128 MiB
Input example #1
begintheescapexecutionatthebreakofdawn
2
escape
execution
Output example #1
beginthatthebreakofdawn
Source 2015 USACO February, Gold