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

using namespace std;

long long calc_linear(const string& t) {
    long long total_bessies = 0;
    vector<int> last(6, -1);
    vector<long long> f(t.size(), 0);
    int k = -1; // Началото на най-десния пълен "bessie" до момента
    
    for (int i = 0; i < (int)t.size(); ++i) {
        if (t[i] == 'e') {
            last[5] = last[4];
            last[1] = last[0];
        } else if (t[i] == 'i') {
            last[4] = last[3];
        } else if (t[i] == 's') {
            last[3] = last[2];
            last[2] = last[1];
        } else if (t[i] == 'b') {
            last[0] = i;
        }
        
        if (last[5] > k) {
            k = last[5];
        }
        
        if (k != -1) {
            f[i] = (k + 1) + (k >= 1 ? f[k - 1] : 0);
        }
        total_bessies += f[i];
    }
    return total_bessies;
}

void solve_subtask2() {
    string t;
    if (!(cin >> t)) return;
    int u;
    cin >> u;
    
    cout << calc_linear(t) << "\n";
    while (u--) {
        int p; char c;
        cin >> p >> c;
        t[p - 1] = c;
        cout << calc_linear(t) << "\n";
    }
}

int main() { solve_subtask2(); return 0; }
