Symmetric Trees (Large)
Time limit5sMemory limit512 MB
Decide whether a color-painted tree can be drawn in the plane with a vertical line of symmetry.
Problem
You are given a tree with vertices, and every vertex is painted with one color. Decide whether the tree can be drawn in the plane so that it has a line of symmetry.
Formally, a tree is line symmetric if every vertex can be assigned a location in the plane so that all four of the following hold.
- All locations are distinct.
- If vertex has color and coordinates , then there is also a vertex of color at . If is 0, then and are the same vertex.
- If edge exists, then edge also exists.
- When each edge is drawn as the straight segment between its two end vertices, two different edges share no point. Two adjacent edges meeting at their common endpoint are allowed.
Input
The first line holds the number of test cases . The test cases follow.
The first line of each test case holds , the number of vertices in the tree.
The next lines each hold one uppercase letter. The -th of them is the color of vertex .
The next lines each hold two integers and (), meaning that the tree has an edge between vertex and vertex . The given edges always form a connected tree.
Limits:
Output
For each test case, print one line holding Case #x: y, where x is the test case number starting from 1, and y is SYMMETRIC when the tree is line symmetric by the definition above and NOT SYMMETRIC when it is not.
Hint
The first test case of the sample input can be drawn like this.

No arrangement of the second test case has a line of symmetry.

Here is one way to draw the third test case with a line of symmetry.
