Petr likes to solve crossword puzzles and other conundrums. Once he found in a newspaper
a new puzzle called "Erudite". There was a square table 4 × 4 filled with
letters. It was required to find in the table as many words as possible;
the words could go up, down, to the right, or to the left and
break at right angles any number of times but they could not have self-intersections.
Petr's friend Vasya told him that it was very silly to spend time solving this
puzzle. He told it was much easier to write a program that would search for
the required words in a dictionary. Petr was offended and told Vasya: "If
you are that clever, write the program yourself. I will cope with the puzzle
myself, the way I like." Help Vasya to get out of the situation.
You should write this program.
Input
The first four lines of the input contain a table 4 × 4 consisting of
lowercase English letters. In the next line there is the number n
(n ≤ 100) of words in the dictionary. These words are given in the
following n lines, one word per line. Each word consists of
lowercase English letters and has length from 1 to 16.
Output
For each word from the dictionary output "YES" if this word can be found in
the table and "NO" otherwise. Use the format given in the sample.
Sample
input | output |
---|
abra
adac
babr
arca
3
abracadabra
ababaab
ababaaba | abracadabra: YES
ababaab: YES
ababaaba: NO
|
Problem Author: Vladimir Yakovlev
Problem Source: IX USU Open Personal Contest (March 1, 2008)