#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, q, up = 0, poc, kr;
    cin >> n >> q;
    vector<char> niz(n);
    for(int i = 0; i < n; i++){
        cin >> niz[i];
        if(niz[i] == '?'){
            up++;
        }
    }

    if(up == n){
        up = 1;
    }

    if(up == 1){
        for(int u = 0; u < q; u++){
            cin >> poc >> kr;
            int duz = kr - poc + 1;

            if(duz % 2 == 0){
                cout << (duz / 2) * (duz / 2) << endl;
            }else{
                cout << ((duz + 1) / 2) * (duz / 2) << endl;
            }
        }
    }else if(up == 0){
        for(int u = 0; u < q; u++){
            cin >> poc >> kr;
            int x = 0;

            for(int i = poc - 1; i < kr; i++){
                if(niz[i] == '6'){
                    for(int j = i; j < kr; j++){
                        if(niz[j] == '7'){
                            x++;
                        }
                    }
                }
            }

            cout << x << endl;
        }
    }
}