Please read problem E before reading this one.
In the previous problem, you were given a tree with labeled edges, and asked to find the possible sources.
In this problem, you are given a tree with unlabeled edges and a set of sources, your task is to label each edge with one of the four directions: up, down, left, or right, such that the set of possible sources (according to the previous problem) matches exactly the given set of sources.
The first line of input contains a single integer $T$ ($1 \le T \le 10^5$), the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ($2 \le n \le 10^5$, $1 \le k \le n$), the number of nodes in the tree and the number of sources.
The second line contains $k$ distinct integers $s_1, s_2, \dots, s_k$ ($1 \le s_i \le n$), the set of possible sources.
Each of the following $n-1$ lines contains two integers $u$ and $v$ ($1 \le u,v \le n$), representing an edge between the two nodes $u$ and $v$.
It is guaranteed that the given graph is a tree, and no node is connected to more than $4$ nodes.
The total sum of $n$ over all test cases doesn't exceed $10^6$.
For each test case, if it is impossible to label the tree, print $-1$ on a single line. Otherwise, print one line with $n-1$ letters representing the labels of the edges in the order they were given in the input. Each label should be one of {U,D,L,R}, representing the four directions: up, down, left, and right, respectively.
Input | Output |
---|---|
3 2 2 2 1 1 2 8 2 3 6 1 2 4 1 1 5 1 3 2 6 8 6 7 6 2 1 1 1 2 Copy
|
L LUDLLUD -1 Copy
|