12792 - Brute-forcibly Finding Tree Anagrams   

Description

Anagrams means "變位字" in Chinese. Assume we have a word  "HEART"  and we want "HEART" to be the level-order sequence and "EARTH" to be the in-order sequence, the tree would exist. However, if we set "EARTH" to be the level-order sequence and "HEART" to be the in-order sequence, then the tree will not exist.

Input

1. Size in the following heap array

2. The given tree in the heap format

3. Number of the following word pairs

Output

Is each pair of words anagrams according to the given tree? Yes or No

Sample Input  Download

Sample Output  Download

Tags




Discuss