# Challenges

Problem Statement

Greg is given a binary tree rooted at X. He is tasked by his supervisor to find the mirror node of any node 't' with respect to X. He doesn't want to disappoint his supervisor and has asked you for help. Please help him find the mirror node of a given node 't' with respect to the root node. If the mirror node doesn't exist, print 'Not Exist'.
NOTE : It is guaranteed that node 't' exists in the tree

Input

The first line of input contains 3 variables, N, Q and X.
Next N lines each contain two integers and one character, first integer represents parent node, second integer represents child node and third character 'L' or 'R' represent left child or right child. (Use these instructions to insert child node in binary tree).
Next Q lines each contain a query, an integer, representing node 't'.

Output

For each query, print the mirror node of 't', if not found, print 'Not Exist' in a newline.

Constraints

1 ≤ N ≤ 1000
1 ≤ Q ≤ 1000
-1000 ≤ nodes(including X) ≤ 1000
It is guaranteed that there are no duplicate values in the tree.

Sample Input

7 3 2 2 3 R 2 4 L 3 5 R 3 6 L 4 7 R 4 8 L 5 9 L 7 9 2

Sample Output

6 Not Exist 2

Dcoded By: Mrudul Sankhere

Solved By: 166

Maximum Marks: 20