Alice was given a tree containing vertices, numbered , by her dad as a present. The tree is rooted at vertex and has edges. Alice made an interesting task with the tree, can you solve it?
For every edge in the tree, Alice wrote either an opening bracket , or a closing bracket , and now she wants you to answer some queries. She will ask queries, and for each query she wants you to check if the brackets on the edges in the path from to listed in order forms a balanced bracket sequence.
For each query your program should output "YES" (without quotes) if the path from to forms a balanced bracket sequence and "NO" (without quotes) otherwise.
A balanced bracket sequence is a string of just brackets that produces a correct mathematical expression when specific numbers and mathematical operations are added to it.
NOTE: In your output YES/NO should be in all uppercase.
INPUT FORMAT
The first line of the input contains an integer () - the number of vertices.
This is followed by lines, each containing an integer, (), and a character - the parent of vertex , and the type of bracket on the edge going from to . The value of runs through all values from to inclusive. It is guaranteed that each set of input data has a correct hanged tree with a root at the vertex .
The next line contains an integer, - the number of queries.
The following lines contain two integers (), and (), - denoting the start and end of a path that needs to be checked.
OUTPUT FORMAT
You should answer all Q queries, hence the output should contain Q lines containing either a string YES or NO.
The tree below corresponds to the tree given as the sample
The path 4 -> 7 corresponds to the bracket sequence (())
The path 7 -> 4 corresponds to the bracket sequence ))((
The path 2 -> 3 corresponds to the bracket sequence ()
The path 5 -> 6 corresponds to the bracket sequence )()(