#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct Node {
    long long len;
    long long ans;
    int trans[6];
    long long cnt[6];
    long long pref[6];
    long long suf_cnt[6];
    long long suf_bessie[6];
};

Node make_node(char c) {
    Node res;
    res.len = 1;
    res.ans = 0;
    string target = "bessie";
    for (int u = 0; u < 6; ++u) {
        if (c == target[u]) {
            if (u == 5) {
                res.trans[u] = 0;
                res.cnt[u] = 1;
            } else {
                res.trans[u] = u + 1;
                res.cnt[u] = 0;
            }
        } else {
            res.trans[u] = u;
            res.cnt[u] = 0;
        }
        res.pref[u] = 0;
        res.suf_cnt[u] = 0;
        res.suf_bessie[u] = 0;
    }
    
    int end_state = res.trans[0];
    long long end_cnt = res.cnt[0];
    res.suf_cnt[end_state] = 1;
    res.suf_bessie[end_state] = end_cnt;
    
    for (int u = 0; u < 6; ++u) {
        res.pref[u] = res.cnt[u];
    }
    return res;
}

Node merge_nodes(const Node& L, const Node& R) {
    Node res;
    res.len = L.len + R.len;
    
    for (int u = 0; u < 6; ++u) {
        res.trans[u] = R.trans[L.trans[u]];
        res.cnt[u] = L.cnt[u] + R.cnt[L.trans[u]];
        res.pref[u] = L.pref[u] + L.cnt[u] * R.len + R.pref[L.trans[u]];
    }
    
    for (int w = 0; w < 6; ++w) {
        res.suf_cnt[w] = R.suf_cnt[w];
        res.suf_bessie[w] = R.suf_bessie[w];
    }
    
    for (int v = 0; v < 6; ++v) {
        int w = R.trans[v];
        res.suf_cnt[w] += L.suf_cnt[v];
        res.suf_bessie[w] += L.suf_bessie[v] + L.suf_cnt[v] * R.cnt[v];
    }
    
    long long cross = 0;
    // Комбинираме суфиксите на лявото дете с префиксите на дясното
    for (int v = 0; v < 6; ++v) {
        cross += L.suf_bessie[v] * R.len + L.suf_cnt[v] * R.pref[v];
    }
    
    res.ans = L.ans + R.ans + cross;
    return res;
}

const int MAXN = 200005;
Node tree[4 * MAXN];
string S;

void build(int node, int start, int end) {
    if (start == end) {
        tree[node] = make_node(S[start]);
        return;
    }
    int mid = (start + end) / 2;
    build(2 * node, start, mid);
    build(2 * node + 1, mid + 1, end);
    tree[node] = merge_nodes(tree[2 * node], tree[2 * node + 1]);
}

void update(int node, int start, int end, int idx, char val) {
    if (start == end) {
        tree[node] = make_node(val);
        return;
    }
    int mid = (start + end) / 2;
    if (idx <= mid) {
        update(2 * node, start, mid, idx, val);
    } else {
        update(2 * node + 1, mid + 1, end, idx, val);
    }
    tree[node] = merge_nodes(tree[2 * node], tree[2 * node + 1]);
}

void solve_full() {
    if (!(cin >> S)) return;
    int U;
    cin >> U;
    
    int n = S.size();
    build(1, 0, n - 1);
    
    cout << tree[1].ans << "\n";
    while (U--) {
        int p; char c;
        cin >> p >> c;
        update(1, 0, n - 1, p - 1, c);
        cout << tree[1].ans << "\n"; // Коренът на дървото съдържа пълния отговор
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve_full(); 
    return 0;
}
