#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define int128 __int128_t
#define pii128 pair<int128,int128>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> bool chmin(T& x, T y){
if(x > y) {
x = y;
return true;
} else return false;
}
template<class T> bool chmax(T& x, T y){
if(x < y) {
x = y;
return true;
} else return false;
}
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME, NUM )
#define GET_COUNT( _1, _2, _3, _4, _5, _6 , COUNT, ... ) COUNT
#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )
#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)
#define rep( ... ) VA_SELECT(rep, __VA_ARGS__)
#define rep2(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, a, b) for (int i = a; i < int(b); i++)
#define rep4(i, a, b, c) for (int i = a; i < int(b); i += c)
#define repll( ... ) VA_SELECT(repll, __VA_ARGS__)
#define repll2(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repll3(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define repll4(i, a, b, c) for (ll i = a; i < (ll)(b); i += c)
#define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__)
#define rrep2(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep3(i, a, b) for (int i = b - 1; i >= a; i--)
#define rrep4(i, a, b, c) for (int i = b - 1; i >= a; i -= c)
#define rrepll( ... ) VA_SELECT(rrepll, __VA_ARGS__)
#define rrepll2(i, n) for (ll i = (ll)(n) - 1; i >= 0ll; i--)
#define rrepll3(i, a, b) for (ll i = b - 1; i >= (ll)(a); i--)
#define rrepll4(i, a, b, c) for (ll i = b - 1; i >= (ll)(a); i -= c)
#define fore(e, v) for (auto&& e : v)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#include<atcoder/all>
using namespace atcoder;
int idx[26];
int nxt[26];
struct node {
int dp[6][6];
node() {
rep (i, 6) rep (j, 6) dp[i][j] = -inf;
}
};
node op(node a, node b) {
node ret;
rep (i, 6) rep (j, 6) {
chmax(ret.dp[i][j], max(a.dp[i][j], b.dp[i][j]));
}
rep (i, 6) rep (j, 5) rep (k, 6) {
if (a.dp[i][j] == -inf || b.dp[j][k] == -inf) continue;
chmax(ret.dp[i][k], a.dp[i][j] + b.dp[j][k] + 2);
}
vector<int> mxa(6, -inf), mxb(6, -inf);
rep (i, 6) rep (j, 6) {
chmax(mxa[i], a.dp[i][j]);
chmax(mxb[j], b.dp[i][j]);
}
rep (i, 6) rep (j, 6) {
chmax(ret.dp[i][j], mxa[i] + mxb[j]);
}
return ret;
}
node e() {
return node();
}
int n, q;
string s;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
cin >> n >> q >> s;
segtree<node, op, e> st(n);
string con = "drmfslt";
string to = "oeiaoai";
string vow = "aiueo";
vector<int> cons(26), vows(26);
rep (i, vow.size()) {
vows[vow[i] - 'a'] = true;
idx[vow[i] - 'a'] = i;
}
rep (i, con.size()) {
cons[con[i] - 'a'] = true;
idx[con[i] - 'a'] = idx[to[i] - 'a'];
}
rep (i, n) {
int ci = s[i] - 'a';
node nd;
if (cons[ci]) {
nd.dp[5][idx[ci]] = 0;
}
if (vows[ci]) {
nd.dp[idx[ci]][5] = 0;
}
st.set(i, nd);
}
rep (_, q) {
char c;
int l, r;
cin >> c >> l >> r;
l--;
if (c == '?') {
node val = st.prod(l, r);
int mx = 0;
rep (i, 6) rep (j, 6) chmax(mx, val.dp[i][j]);
cout << r - l - mx << '\n';
} else {
string t;
cin >> t;
rep (i, t.size()) {
int ci = t[i] - 'a';
node nd;
if (cons[ci]) {
nd.dp[5][idx[ci]] = 0;
}
if (vows[ci]) {
nd.dp[idx[ci]][5] = 0;
}
st.set(l + i, nd);
}
}
}
}