#include <cstdio> #include <vector> #include <cstring> #include <string> #include <iostream> using namespace std; #define NMAX 100002 int best; vector<int> G[NMAX]; char S[NMAX], W[NMAX]; int N, T, x, y; void dfs(int nod, string p, string pp) { W[nod] = 1; for (vector<int>::iterator it = G[nod].begin(); it != G[nod].end(); ++it) if (!W[*it]) dfs(*it, p+S[(*it)-1], S[(*it)-1]+pp); // cout << nod << " " << p << " " << pp << "\n"; if (p.length() > best && p == pp) { best = p.length(); } } int main() { //freopen("test.in", "r", stdin); scanf("%d", &T); while (T--) { scanf("%d\n", &N); for (int i=1; i<=N; ++i) G[i].clear(); memset(W, 0, sizeof(W)); best = 0; fgets(S, NMAX, stdin); for (int i=1; i<N; ++i) { scanf("%d %d", &x, &y); G[x].push_back(y); G[y].push_back(x); } string p(""); string pp(""); p += S[0]; pp += S[0]; dfs(1, p, pp); printf("%d\n", best); } return 0; }