#P1771D. Hossam and (sub-)palindromic tree
Hossam and (sub-)palindromic tree
No submission language available for this problem.
Description
Hossam has an unweighted tree with letters in vertices.
Hossam defines as a string that is obtained by writing down all the letters on the unique simple path from the vertex to the vertex in the tree .
A string is a subsequence of a string if can be obtained from 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 as a subsequence of , 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 as a sub-palindrome of , which has the maximal length among all sub-palindromes of . 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 maximum sub-palindromes.
Help Hossam find the length of the longest maximal sub-palindrome among all in the tree .
Note that the sub-palindrome is a subsequence, not a substring.
The first line contains one integer () — the number of test cases.
The first line of each test case has one integer number () — the number of vertices in the graph.
The second line contains a string of length , the -th symbol of which denotes the letter on the vertex . It is guaranteed that all characters in this string are lowercase English letters.
The next lines describe the edges of the tree. Each edge is given by two integers and (, ). These two numbers mean that there is an edge in the tree. It is guaranteed that the given edges form a tree.
It is guaranteed that sum of all doesn't exceed .
For each test case output one integer — the length of the longest maximal sub-palindrome among all .
Input
The first line contains one integer () — the number of test cases.
The first line of each test case has one integer number () — the number of vertices in the graph.
The second line contains a string of length , the -th symbol of which denotes the letter on the vertex . It is guaranteed that all characters in this string are lowercase English letters.
The next lines describe the edges of the tree. Each edge is given by two integers and (, ). These two numbers mean that there is an edge in the tree. It is guaranteed that the given edges form a tree.
It is guaranteed that sum of all doesn't exceed .
Output
For each test case output one integer — the length of the longest maximal sub-palindrome among all .
Note
In the first example the maximal subpalindromes are "aaa" with letters in vertices , or "aca" with letters in vertices .

In the second example there is only one maximal palindrome "bacab" with letters in vertices .
