Word equations#4132

Word equations

1 second
128 megabytes
Very easy

You are given a text and a pattern . You want to check if you can erase some of the letters of so that the remaining symbols produce exactly . For example, the word programming can be partially erased to obtain pong or program or roaming (but not map, as the letters must remain in the same order). Both words consist of small letters of the English alphabet only.

There is just one catch: the text is encoded by a system of equations. The equations use special symbols (every symbol is denoted by a word in capital letters), each of them encoding some word over the alphabet {a,...,z}. Each equation is of one of the following forms:

A = a word over {a,...,z}

or

A = B + C

where A, B, C can be any special symbols, and the + sign denotes the concatenation of words. The system is:

Such a system always has a unique solution. For example, in the system:

the symbol START encodes the word goodtimesbadtimes.

Given a single word as the pattern, a system of equations, and one particular starting symbol of this system, determine whether the pattern is present in the word encoded by .

Input

The first line contains the number of test cases . The descriptions of the test cases follow:

Each test case starts with a line containing a single integer (1 \le k \le 500) - the number of equations. The next lines contain equations. Each of them has one of the two forms given in the problem statement, with spaces separating words, plus signs, and equation signs. Each word (including symbol names) is at least one and at most five characters long.

The next line contains a single special symbol (a word in capital letters), while the final line contains a non-empty word of at most lowercase letters. These are the starting symbol and the pattern to find, respectively.

Output

For each test case print the answer in a separate line: YES if the pattern appears in the given encoded word, and NO otherwise.

Examples

Example 1

Loading
Loading