#include <fstream>
#include <iostream>
#include <vector>
#include <bitset>
#include <string.h>
#include <algorithm>


using namespace std;

const char infile[] = "input.in";
const char outfile[] = "output.out";

ifstream fin(infile);
ofstream fout(outfile);

const int MAXN = 100005;
const int oo = 0x3f3f3f3f;
const int M = (1<<30)-1;
const int S = 27;
typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;
int N, power[MAXN];
Graph g;
char C[MAXN];
int Ans;

inline void DFs(int Node, int father, int hash1, int hash2, int level) {
    if(hash1 == hash2)
        Ans = max(Ans, level);
    for(It it = g[Node].begin(), fin = g[Node].end(); it != fin ; ++ it)
        if(*it != father)
            DFs(*it, Node, (hash1 + 1LL * power[level] * C[*it]) & M, (1LL * hash2 * S + C[*it]) & M, level + 1);
}

int main() {
    cin.sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
    freopen(infile, "r", stdin);
    freopen(outfile, "w", stdout);
    #endif
    int T;
    cin >> T;
    power[0] = 1;
    for(int i = 1 ; i < MAXN ; ++ i)
        power[i] = (1LL * power[i - 1] * S)&M;
    while(T -- ) {
        cin >> N >> C + 1;
        for(int i = 1 ; i <= N ; ++ i) {
            C[i] -= ('a' - 1);
            vector <int> ().swap(g[i]);
        }
        for(int i = 1 ; i < N ; ++ i) {
            int x, y;
            cin >> x >> y;
            g[x].push_back(y);
            g[y].push_back(x);
        }
        Ans = 0;
        DFs(1, 0, C[1], C[1], 1);
        cout << Ans << '\n';
    }
    return 0;
}