#P1771D. Hossam and (sub-)palindromic tree

    ID: 8125 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>brute forcedata structuresdfs and similardpstringstrees*2100

Hossam and (sub-)palindromic tree

No submission language available for this problem.

Description

Hossam has an unweighted tree GG with letters in vertices.

Hossam defines s(v,u)s(v, \, u) as a string that is obtained by writing down all the letters on the unique simple path from the vertex vv to the vertex uu in the tree GG.

A string aa is a subsequence of a string ss if aa can be obtained from ss by deletion of several (possibly, zero) letters. For example, "dores", "cf", and "for" are subsequences of "codeforces", while "decor" and "fork" are not.

A palindrome is a string that reads the same from left to right and from right to left. For example, "abacaba" is a palindrome, but "abac" is not.

Hossam defines a sub-palindrome of a string ss as a subsequence of ss, that is a palindrome. For example, "k", "abba" and "abhba" are sub-palindromes of the string "abhbka", but "abka" and "cat" are not.

Hossam defines a maximal sub-palindrome of a string ss as a sub-palindrome of ss, which has the maximal length among all sub-palindromes of ss. For example, "abhbka" has only one maximal sub-palindrome — "abhba". But it may also be that the string has several maximum sub-palindromes: the string "abcd" has 44 maximum sub-palindromes.

Help Hossam find the length of the longest maximal sub-palindrome among all s(v,u)s(v, \, u) in the tree GG.

Note that the sub-palindrome is a subsequence, not a substring.

The first line contains one integer tt (1t2001 \le t \le 200) — the number of test cases.

The first line of each test case has one integer number nn (1n21031 \le n \le 2 \cdot 10^3) — the number of vertices in the graph.

The second line contains a string ss of length nn, the ii-th symbol of which denotes the letter on the vertex ii. It is guaranteed that all characters in this string are lowercase English letters.

The next n1n - 1 lines describe the edges of the tree. Each edge is given by two integers vv and uu (1v,un1 \le v, \, u \le n, vuv \neq u). These two numbers mean that there is an edge (v,u)(v, \, u) in the tree. It is guaranteed that the given edges form a tree.

It is guaranteed that sum of all nn doesn't exceed 21032 \cdot 10^3.

For each test case output one integer — the length of the longest maximal sub-palindrome among all s(v,u)s(v, \, u).

Input

The first line contains one integer tt (1t2001 \le t \le 200) — the number of test cases.

The first line of each test case has one integer number nn (1n21031 \le n \le 2 \cdot 10^3) — the number of vertices in the graph.

The second line contains a string ss of length nn, the ii-th symbol of which denotes the letter on the vertex ii. It is guaranteed that all characters in this string are lowercase English letters.

The next n1n - 1 lines describe the edges of the tree. Each edge is given by two integers vv and uu (1v,un1 \le v, \, u \le n, vuv \neq u). These two numbers mean that there is an edge (v,u)(v, \, u) in the tree. It is guaranteed that the given edges form a tree.

It is guaranteed that sum of all nn doesn't exceed 21032 \cdot 10^3.

Output

For each test case output one integer — the length of the longest maximal sub-palindrome among all s(v,u)s(v, \, u).

Sample Input 1

2
5
abaca
1 2
1 3
3 4
4 5
9
caabadedb
1 2
2 3
2 4
1 5
5 6
5 7
5 8
8 9

Sample Output 1

3
5

Note

In the first example the maximal subpalindromes are "aaa" with letters in vertices 1,3,51, \, 3, \, 5, or "aca" with letters in vertices 1,4,51, \, 4, \, 5.

The tree from the first example.

In the second example there is only one maximal palindrome "bacab" with letters in vertices 4,2,1,5,94, \, 2, \, 1, \, 5, \, 9.

The tree from the second example.