VAN DINSKY#3850

VAN DINSKY

5 seconds
256 megabytes
Easy

You must help would-be painter Vincent van Dinsky mix colors for his paintings. His master gave him a book of color mixing rules plus a color palette, and told him to produce the set of colors that are required for a painting, by experimenting until he finds the minimum number of color mixes that is required for each color in the painting.

Notes:

Input

Input consists of, in the following order:

  • all the color mixing rules in the book

  • an empty line

  • one or several data sets (painting tasks), made of two lines each:

    • all the colors available initially on the palette

    • all the colors required for the painting

Output

You should produce an output that contains one line for each painting (i.e. each data set); on that line, for each color in the painting, the minimum number of color mixes that will produce the desired color (starting from the colors available initially on the palette; the result is if it's impossible to obtain the desired color).

You can assume that the input is correct, there are less than color mixing rules in the rule book and less than colors.

Examples

Example 1

Loading
Loading