#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int cost( string s, int c )
{

    int mx = 0;
    int current = 0;
    int nule = 0;
    int jedinice = 0;
    int kost = 0;
    for(int i = 0; i < s.length(); i++)
    {
        if(s[i] == '1')
        {
            current++;
            jedinice++;
            nule = 0;
            if(current > mx)
                mx = current;

        }
        else
        {

            current--;
            nule++;
            if(current < 0 || nule >= c)
            {

                if(mx > c)
                    kost += jedinice - mx + c;
                else
                    kost += jedinice;

                jedinice = 0;
                mx = 0;
                current = 0;
                nule = 0;
            }
        }
    }
     if(mx > c)
            kost += jedinice - mx + c;
        else
            kost += jedinice;
    return kost;
}

int main() {
	//freopen("in.txt", "r", stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n,c,q;
	cin >> n >> c >> q;
    string s;
    cin >> s;
    int le, ri;

    while (q--) {
        cin >> le >> ri;
        for (int i = le-1; i < ri; i++) {
            s[i] = (s[i]-'0'+1)%2+'0';
        }
        cout << cost(s, c) << endl;
    }




	return 0;
}