#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define int long long
#define lc p<<1
#define rc p<<1|1
using namespace std;
const int N = 2e5 + 7;
string s1, s2;
struct Node {
int L, R;
int r, re, red;
int e, ed;
int d;
}t[N << 2][2];
void pushup(int p, int id) {
t[p][id].r = t[lc][id].r + t[rc][id].r;
t[p][id].e = t[lc][id].e + t[rc][id].e;
t[p][id].d = t[lc][id].d + t[rc][id].d;
t[p][id].re = t[lc][id].re + t[rc][id].re + t[lc][id].r * t[rc][id].e;
t[p][id].ed = t[lc][id].ed + t[rc][id].ed + t[lc][id].e * t[rc][id].d;
t[p][id].red = t[lc][id].red + t[rc][id].red;
t[p][id].red += t[lc][id].r * t[rc][id].ed + t[lc][id].re * t[rc][id].d;
}
void update(int p, int x, char c, int id) {
if (t[p][id].L == t[p][id].R && t[p][id].L == x) {
t[p][id].d = t[p][id].e = t[p][id].r = 0;
if (c == 'r')t[p][id].r = 1;
if (c == 'e')t[p][id].e = 1;
if (c == 'd')t[p][id].d = 1;
return;
}int m = t[p][id].L + t[p][id].R >> 1;
if (x <= m) {
update(lc, x, c, id);
}
else {
update(rc, x, c, id);
}pushup(p, id);
}
int query(int id) {
return t[1][id].red;
}
void build(int p, int l, int r, string who, int id) {
t[p][id].L = l; t[p][id].R = r;
if (l == r) {
if (who[l] == 'r')t[p][id].r = 1;
if (who[l] == 'e')t[p][id].e = 1;
if (who[l] == 'd')t[p][id].d = 1;
return;
}int m = l + r >> 1;
build(lc, l, m, who, id);
build(rc, m + 1, r, who, id);
pushup(p, id);
}
void solve() {
int n, q; cin >> n >> q;
cin >> s1 >> s2; s1 = ' ' + s1; s2 = ' ' + s2;
build(1, 1, n, s1, 0);
build(1, 1, n, s2, 1);
for (int i = 1; i <= q; i++) {
int x; cin >> x;
if (s1[x] != s2[x]) {
update(1, x, s2[x], 0);
update(1, x, s1[x], 1);
swap(s1[x], s2[x]);
}
cout << query(0) - query(1) << "\n";
}
}
signed main() {
solve();
return 0;
}