#include <bits/stdc++.h>
#define pb push_back
#define ott(i,l,r) for (int i = l; i <= r; i ++)
#define tto(i,l,r) for (int i = r; i >= l; i --)
using namespace std;
using ll = long long;
int read () {
int x = 0; bool f = 0; char c = getchar ();
while (!isdigit (c)) f |= (c == '-'), c = getchar ();
while (isdigit (c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar ();
if (f) x = -x; return x;
}
const int N = 1e6 + 110;
int n, m, q, idx, B, lim, res;
vector <int> e[N], E[N];
int up[N], dn[N];
int fa[N][22], dfn[N], dep[N];
char s[N];
void dfs0 (int u) {
dfn[u] = ++ idx, dep[u] = dep[fa[u][0]] + 1;
ott (j, 1, 20) fa[u][j] = fa[fa[u][j - 1]][j - 1];
for (int v : e[u]) dfs0 (v);
return ;
}
int lca (int x, int y) {
if (dep[x] < dep[y]) swap (x, y);
tto (i, 0, 20) if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
if (x == y) return x;
tto (i, 0, 20) if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
return fa[x][0];
}
struct OPT {
int x; char c;
} a[N];
struct BLOCK {
int ac, now, sum;//ac = 'A'count
int s[1100];
void ins (int v) {
if (v >= now) ++ sum;
++ s[v + B];
return ;
}
void add (int v) {
if (v == 1) sum += s[(v) + B];
else if (v == -1)
return ;
}
void clear () {
ac = 0, now = sum = 0;
memset (s, 0, sizeof s);
return ;
}
} b[N];
int t[N], FA[N], bl[N];//belong&below
bool cmp (int x, int y) {
return dfn[x] < dfn[y];
}
void fuck (int u, int z) {
bl[u] = z;
for (int v : e[u]) fuck (v, z);
return ;
}
void cpr (int u) {
int oth = 0;
for (int v : e[u]) {
if (bl[v]) cpr (v);
else {
if (!oth) oth = v, t[++ t[0]] = v;
fuck (v, oth);
}
}
return ;
}
void red (int u) {
dn[u] = 0;
for (int v : e[u]) {
up[v] = up[u] + (s[u] != 'C');
red (v);
dn[u] += dn[v] + (s[v] != 'A');
}
if (s[u] == 'A') res += dn[u];
if (s[u] == '?') res += max (0, dn[u] - up[u]);
return ;
}
void cup (int u, int val) {//-
for (int v : E[u]) {
if (bl[v] < 0) {
if (s[v] == '?') res -= max (0, dn[v] - up[v]);
up[v] += val;
if (s[v] == '?') res += max (0, dn[v] - up[v]);
}
else {
res -= sum;
b[bl[u]].add (val), res += b[bl[u]].ac * val;
res += sum;
}
cup (v, val);
}
return ;
}
void cdn (int u, int val) {
if (!u) return ;
if (bl[u] < 0) {
if (s[u] == '?') res -= max (0, dn[u] - up[u]);
dn[u] += val; if (s[u] == 'A') res += val;
if (s[u] == '?') res += max (0, dn[u] - up[u]);
}
else {
res -= sum;
b[bl[u]].add (-val), res += b[bl[u]].ac * val;
res += sum;
}
cdn (FA[u], val);
return ;
}
void sol () {
ott (i, 1, m) t[++ t[0]] = a[i].x;
sort (t + 1, t + 1 + t[0], cmp);
ott (i, 2, m) t[++ t[0]] = lca (t[i - 1], t[i]); t[++ t[0]] = 1;
sort (t + 1, t + 1 + t[0]), t[0] = unique (t + 1, t + 1 + t[0]) - t - 1;
ott (i, 1, t[0]) bl[t[i]] = -t[i];//区分
ott (i, 1, t[0]) {
int z = fa[t[i]][0], now = z;
while (!bl[now]) {
bl[now] = z;
now = fa[now][0];
}
}
cpr (1), sort (t + 1, t + 1 + t[0], cmp);
ott (i, 1, n) {
assert (bl[i]);
if (bl[i] < 0) continue;
if (s[i] == 'A') ++ b[bl[i]].ac;
else if (s[i] == '?') b[bl[i]].ins (dn[i] - up[i]);
}
ott (i, 2, t[0]) E[FA[t[i]] = lca (t[i - 1], t[i])].pb (t[i]);
ott (i, 1, m) {
int x = a[i].x; char c = a[i].c;
if (s[x] != 'C') cup (x, -1); if (s[x] != 'A') cdn (FA[x], -1);
if (s[x] == 'A') res -= dn[x];
if (s[x] == '?') res -= max (0, dn[x] - up[x]);
s[x] = c;
if (s[x] == 'A') res += dn[x];
if (s[x] == '?') res += max (0, dn[x] - up[x]);
if (s[x] != 'C') cup (x, -1); if (s[x] != 'A') cdn (FA[x], -1);
printf ("%d\n", res);
}
ott (i, 1, t[0]) FA[t[i]] = 0, b[bl[t[i]]].clear ();
ott (i, 1, n) bl[i] = 0, E[i].clear ();
t[0] = 0;
return ;
}
int main () {
n = read (), q = read (), cin >> s + 1; ott (i, 2, n) e[fa[i][0] = read ()].pb (i);
B = (int)sqrt (q), lim = B << 1 | 1; ott (i, 1, n) b[i].clear ();
dfs0 (1), red (1); ott (i, 1, q) {
int x = read (); char c = getchar ();
a[++ m] = {x, c};
if (i % B == 0 || i == q) {
sol ();
m = 0, res = 0, red (1);
}
}
return 0;
}