Symmetric Trees (Small)

Decide whether a colored tree with at most 12 vertices admits a planar straight-line drawing with a vertical line of symmetry.

Medium6Brute forceTreeBacktrackingNo attempts yetTime limit5sMemory limit512 MB

Problem

You are given a tree with NN vertices, and each vertex has a 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 conditions below hold at once.

  • No two vertices share a location.
  • If vertex viv_i has color CC and location (xi,yi)(x_i, y_i), then a vertex viv_i' with color CC and location (xi,yi)(-x_i, y_i) also exists. If xix_i is 00, then viv_i and viv_i' are the same vertex.
  • If edge (vi,vj)(v_i, v_j) exists, then edge (vi,vj)(v_i', v_j') also exists.
  • When each edge is drawn as the straight segment between its two endpoints, two different segments share no point except an endpoint shared by two adjacent edges.

Input

The first line contains the number of test cases TT. The TT test cases follow.

The first line of each test case contains the number of vertices NN in the tree.

The next NN lines each contain one uppercase letter. The ii-th of these lines is the color of vertex ii.

The next N1N-1 lines each contain two integers ii and jj (1i<jN1 \le i < j \le N). This means the tree has an edge between vertex ii and vertex jj. The given edges always form a connected tree.

Limits

  • 1T1001 \le T \le 100
  • 2N122 \le N \le 12

Output

For each test case, print one line in the form "Case #x: y", where xx is the test case number starting from 11, and yy is SYMMETRIC if the tree is line symmetric by the definition above and NOT SYMMETRIC otherwise.

Hint

The first test case can be drawn like this.

No placement of the vertices of the second test case gives a line of symmetry.

One way to draw the third test case with a line of symmetry is shown below.