The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 406 Weeks Ago, 2 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Little Avani had been reading about magical tales a lot. Being fascinated by the power of magic tricks, she decided to learn magic. She bought a book which contained N magic tricks. Each magic trick is described as a string S consisting of characters from the set {a,b,c,d} only. Being very little, she was unable to understand any of the magic tricks. She put a lot of effort to figure out how to use those tricks. She then found that each magic trick Si is dependent on another magic trick Sj such that:
Now she has Q queries. Each query consists of a magic trick. For each query she wants to know the magic trick it is dependent on. Help her learn the magic tricks and she will give you lots of goodies in return.
The first line contains a single integer N denoting the number of magic tricks in the book.
N lines follow. Each line contains description of a magic trick.
Next line contains an integer Q denoting the number of magic tricks Avani is interested in.
Q lines follow. Each line contains a magic trick.
For each query, output the magic trick which it is dependent on. If there is no such magic trick, then output -1.
Input:
5 aa abb bdc cda dacc 4 bdc cda aa abb
Output:
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll