#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void solve(int cs) {
int n;
cin >> n;
string s;
cin >> s;
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v, --u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
auto ispal = [&](string t) -> bool {
for (int i = 0, j = t.size() - 1; j > i; i++, j--) if (t[i] != t[j]) return false;return true;
};
int q;
cin >> q;
while (q--) {
int i;char c;
cin >> i >> c;
s[i - 1] = c;
int res = 1;
string t; t += s[0];
auto dfs = [&](auto &&self, int node, int par) -> void {
if (ispal(t)) {
res = max(res, (int)t.size());
}
for (auto &nodes : g[node]) {
if (nodes != par) {
t += s[nodes];
self(self, nodes, node);
t.pop_back();
}
}
};
dfs(dfs, 0, -1);
cout << res << "\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc = 1;
// cin >> tc;
for (int cs = 1; cs <= tc; cs++) {
solve(cs);
}
return 0;
}