#include <bits/stdc++.h>
using namespace std;
const int mxN = 1003;
vector<vector<int>> g(mxN);
string s;
int res;
bool ispal(string t) {
for (int i = 0, j = t.size() - 1; j > i; i++, j--)
if (t[i] != t[j])
return false;
return true;
}
void dfs(int node, int par, string path) {
path += s[node];
if (ispal(path))
res = max(res, (int)path.size());
for (auto &next_node : g[node]) {
if (next_node != par) {
dfs(next_node, node, path);
}
}
path.pop_back();
}
void solve() {
int n, q;
cin >> n >> s;
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);
}
cin >> q;
while (q--) {
int x;
char c;
cin >> x >> c;
if (c != s[x - 1]) {
s[x - 1] = c;
string t;
res = 0;
dfs(0, -1, t);
}
cout << res << "\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}