Heta is a conventional name for the historical Greek alphabet letter Eta (Η) and several of its variants, when used in their original function of denoting the consonant /h/ (Wikipedia). Because of whispers of N'Zoth the corruptor, Heta now wants to destroy all existing alphabets (fiction).
Heta has a spell book containing spells to delete a string. There are several spells in that book. Armed with the spellbook, Heta starts his journey to complete his mission. On his way, Heta found a very long string. To delete that string, Heta reads that string letter by letter from the first letter. If at any point he found a substring that's present in his spellbook, that spell will be cast and that substring will be destroyed. Then he continues until he reach the end of that string and no more spell can be used. If there are multiple spells that can be used in one time, the spell that appears first in the book is used. Determine what's left of the very long string after Heta is done!
First line is a string containing A-Z. String can contain from 1 to 100000 characters. Next line of input is N, the number of spells in the spellbook 1 ≤ N ≤ 100). Next N lines contain spells sorted by appearance in the spellbook. Each spell is a string containing A-Z with a length from 1 to 100.
One line containing the string after Heta is done doing his magic.
KUKUKAKIKUKAKEKKUKAKAKKUKAKUKAKU 2 KEK UK
HEATHLEDGER 2 HEATH LEDGER
KAPKAPPAPAK 1 KAPPA
CABAI 3 ABA AB B
Problem source: Sphere Online Judge