Researchers from the Foundation Against Cancer (FCC) announced a revolutionary discovery in Chem- istry: they discovered how to make carbon atoms bind to any number of other carbon atoms, enabling the creation of more complex molecules than those formed by tetravalent carbon. According to the FCC, this will allow the development of new drugs that may be crucial in fighting cancer. Currently, the FCC can only synthesize molecules that have a single bonds between the carbon atoms and contain no cycles in their structures: for example, the FCC can synthesize molecules (a), (b) and (c) below, but not the molecule (d). Due to thermal agitation, the same molecule can take several formats. Two molecules are equivalent if it is possible to move the atoms of the molecules, without breaking any of the existing chemical bonds or creating new chemical bonds, so that both molecules are exactly equal. For example, in the figure above, molecule (a) is not equivalent to molecule (b), but is equivalent to molecule (c). You should write a program that, given the structures of two molecules, determines if they are equivalent. Input The input contains several test cases. The first line of a test case contains an integer N indicating the number of atoms in the two molecules. The atoms are identified by integers from 1 to N. Each the following 2N − 2 lines describes a chemical bonds between two atoms: the first N − 1 lines describe the chemical bonds of the first molecule, the last N − 1 lines describe the chemical bonds of the second molecule. Each line contains two integers A and B indicating that a chemical bond exists between atoms A and B. Output For each test case your program must print a single line, containing a single character: ‘S’ if the molecules are equivalent or ‘N’ otherwise. Restrictions • 2 ≤ N ≤ 104 • 1≤A,B≤N Sample Input 7 12 23
2/2 34 45 62 73 12 23 34 45 62 74 6 12 13 24 25 36 24 53 64 14 56 Sample Output N S