Favorite Tree
InterviewTime limit0.1sMemory limit1024 MB
Given two trees T1 and T2, decide whether T1 contains a connected subtree that is isomorphic to T2.
Problem
Telio learned about tree isomorphism and then wondered how many trees out there contain his favorite tree.
Given two trees and , determine whether has a subtree that is isomorphic to .
Two trees are isomorphic if their vertices can be labeled so that the two trees become exactly the same. For example, a tree with edges is isomorphic to a tree with edges .
The figure below shows on the left and on the right. The subtree of formed by all vertices except vertex 5 is isomorphic to .

Input
The input has two groups of lines. The first group describes , and the second group describes .
Each group starts with an integer (), the number of vertices. Vertices are labeled with distinct integers from 1 to . Each of the next lines contains two integers and (, ), meaning the tree has the edge .
The input always describes two valid trees.
Output
Print a single line containing the uppercase letter "Y" if has a subtree isomorphic to , and "N" otherwise.