#include <stdio.h>
#include <string.h>

#include <vector>

using namespace std;

int n, sol;
char s[100005];
int pow1[100005], pow2[100005], level[100005], viz[100005];
vector <int> v[100005];
const int mod = 1000000007;

void dfs (int nod, int ohash1, int ohash2, int ohash3, int ohash4)
{
	int hash1 = ((long long)ohash1 * 29 + s[nod]) % mod;
	int hash2 = (ohash2 + (long long)pow1[level[nod]] * s[nod]) % mod;
	if (hash1 == hash2)
		sol = max (sol, level[nod]);
	
	int hash3 = ((long long)ohash3 * 31 + s[nod]) % mod;
	int hash4 = (ohash4 + (long long)pow2[level[nod]] * s[nod]) % mod;
	if (hash3 == hash4)
		sol = max (sol, level[nod]);
	
	viz[nod] = 1;
	for (vector <int> :: iterator it = v[nod].begin(); it != v[nod].end(); it ++)
		if (!viz[*it])
		{
			level[*it] = level[nod] + 1;
			dfs (*it, hash1, hash2, hash3, hash4);
		}
}

int main ()
{
#ifndef ONLINE_JUDGE
	freopen ("mind4.in", "r", stdin);
	freopen ("mind4.out", "w", stdout);
#endif

	int t, i, x, y;
	scanf ("%d", &t);
	while (t --)
	{
		memset (viz, 0, sizeof (viz));
		sol = 0;
		scanf ("%d\n", &n);
		gets (s + 1);
		for (i = 1; i <= n; i ++)
			s[i] -= 'a';
		pow1[0] = 1;
		pow2[0] = 1;
		for (i = 1; i < n; i ++)
		{
			scanf ("%d %d", &x, &y);
			v[x].push_back (y);
			v[y].push_back (x);
			pow1[i] = (pow1[i - 1] * 29) % mod;
			pow2[i] = (pow2[i - 1] * 31) % mod;
		}
		dfs (1, 0, 0, 0, 0);
		printf ("%d\n", sol + 1);
	}
	return 0;
}