The code of the lock
Coward, Dunce, and Experienced spent three days meticulously preparing for their upcoming heist. As is often the case, new details emerged at the last minute: a new electronic lock had been installed at the warehouse.
Luckily, the robbers discovered that the lock code could be derived from a string S, composed of characters 'a'-'z', and an array of strings called conversions. Each string in conversions follows the format "s1-s2", where s1 and s2 are strings of characters 'a'-'z'.
To extract the lock code from the string S, you must process each element of the conversions array in order, from the first to the last. For each element "s1-s2", perform the following actions:
If the string S contains at least one occurrence of s1 as a substring, replace the first (leftmost) occurrence of s1 in S with s2.
If S does not contain s1 as a substring, append s2 to the end of S.
With time running short before the operation begins, and manually determining the code being too time-consuming, the robbers first turned to programmers from the "Operation Y.MEDIUM" contest, and now they seek help from participants of the New Year's marathon on New Year's Eve 2011.
Input
The first line contains the string S. The second line contains the number N, representing the number of elements in the conversions array. The subsequent lines list the elements of the conversions array.
The string S consists of between 1 and 50 characters, each being 'a'..'z'. The conversions array contains between 1 and 50 elements. Each element in the conversions array is formatted as "s1-s2", where s1 and s2 are strings of 1 to 10 characters, each being 'a'..'z'.
Output
Output the string that represents the lock code.