Secret Chamber at Mount Rushmore
InterviewTime limit1sMemory limit512 MB
Given directed letter translations, decide for each pair of words whether every letter of the first can reach the matching letter of the second.
Problem

Mount Rushmore has a huge stone sculpture of four U.S. presidents. Very few people know that the monument also contains a secret chamber. It sounds like a movie plot, but the chamber is real. It sits behind the head of Abraham Lincoln and was designed as a Hall of Records for important U.S. historical documents and artifacts. Historians say that construction stopped in 1939 and that the unfinished chamber was left untouched until the late 1990s, but that is not the whole story.
In 1982 the archaeologist S. Dakota Jones visited the monument in secret and found that the chamber had in fact been completed and then kept confidential. That looked suspicious, so she poked around and found a hidden vault with documents inside. The documents made no sense at all. She suspected that they had been written in a code, but nothing she tried deciphered them.
Earlier this week, while she was in the area for the world finals, Dr. Jones finally found the key in Connolly Hall of SDSM&T. It is a document listing translations of letters. Some letters have more than one translation, and some have none. By applying these translations to individual letters of the unreadable documents over and over, she may be able to recover originals such as the Declaration of Independence and the Constitution. She needs your help.
You are given the possible translations of letters and a list of pairs of an original word and a deciphered word. Decide whether the two words in each pair match. Two words match when they have the same length and each letter of the first word can be turned into the letter at the same position of the second word by applying the available translations zero or more times.
Input
The first line contains two integers () and (), where is the number of letter translations and is the number of word pairs.
Each of the next lines contains two distinct space separated letters and , meaning that the letter can be translated to the letter . Each ordered pair appears at most once.
Each of the following lines contains one word pair to check. Translations and words use only the lowercase letters a to z, and every word has at least 1 and at most 50 letters.
Output
For each word pair, print yes if the two words match and no otherwise, one answer per line.