New Year's '17 P4 - Christmas Cozonac

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 1.0s
Memory limit: 128M

Author:
Problem type

This year, the day before Christmas Eve, Gigel watched all day his lovely mother working on cozonac. In the morning of that day, Gigel's mother told him all the recipes that she was going to use, and he wrote them in his notebook. Then he started watching his mother work, and wrote all the steps involved. However, every year, after baking, the cozonac cakes get scrambled and no one knows what filling each one has.

So, this year, Gigel wants to put the cozonac cakes in different bags and label them. But he is lost in his notebook, after making so many, so he needs your help. He will write the things in his notebook as input, and he expects you to tell him the name of the final product.

Input Specification

On the first line of input you will find N, the number of combinations Gigel found out from his mother.
On the next N lines of input you will find a combination. The combinations will look like ( i1 + i2 + ... + ix ) = rez, where i_1, i_2, \dots, i_x are the ingredients, rez is the result and every different element is separated by a space.
On the next line of input you will find C, the number of cozonac cakes baked by Gigel's mother.
On the next C lines of input you will find the recipe for that particular cozonac. The formatting is the same, but now you can also have other combinations as ingredients.

Output Specification

For each cozonac recipe, print on a different line the name of it.

Constraints and notes

  • 3 \le N \le 120\,000
  • 1 \le C \le 200
  • Combination ( i_1 + i_2 + i_3 ) is \equiv to ( i_2 + i_1 + i_3 ).
  • The names of the ingredients will not exceed a length of 25 characters.
  • Each recipe will have no more than 16 ingredients.

Sample Input

6
( BakerYeast + Sugar ) = YeastReaction
( Flour + Eggs + Milk + YeastReaction + Butter ) = Dough
( Dough + Time ) = MoreDough
( MoreDough + Knife ) = MoreDoughPart
( Cocoa + Sugar + Egg + Egg ) = CocoaFilling
( MoreDoughPart + CocoaFilling ) = CocoaCozonac
2
( ( Cocoa + Egg + Sugar + Egg ) + ( Knife + ( ( Flour + Eggs + ( BakerYeast + Sugar ) + Milk + Butter ) + Time ) ) )
( ( Knife + ( ( Flour + Eggs + ( BakerYeast + Sugar ) + Milk + Butter ) + Time ) ) + CocoaFilling )

Sample Output

CocoaCozonac
CocoaCozonac

Comments

There are no comments at the moment.