13456 - Walk on the tree"S"   

Description

 

You are given some binary trees of total N vertices numbered from 1 to N.

And M branches connect those trees.

There are Q questions.

Print every direction if you want to walk from node A to node B (Guaranteed only one path if it can be reached),

or "oops" if you can't walk there

P: move to parent

R: move to right child

L: move to left child

B: move to branch

 

Limit:

Testcases 1~2: only one tree, M = 0.

Testcase 3: no more than two trees.

Testcases 4~5: N, M <= 3000.

Input

The first line contains two integers N, M (2N, M3000).

Each of the next N lines contains 2 integers, representing the left child and the right child of the i th node. (and 0 means empty)

Each of the next M lines contains 2 intergers Bi, Bj, representing there is a branch between the Bi node and the Bj node.

The next line contains an integer Q (1Q3000).

Each of the next Q lines contains two integers, A, B.

Output

For each question, output every direction that walks from node A to node B, or "oops" if you can't walk there. 

Remember to add a new line in the end of each question.

Sample Input  Download

Sample Output  Download

Tags




Discuss