#include <bits/stdc++.h>

using namespace std;

int brainrot_counter_kms(string kms){
    int l=kms.size();
    vector<int> indeksi;
    int brainrot_factor=0;
    int broj_sestica=0;
    for(int z =0;z<l;z++){
        if(kms[z]=='6'){
            broj_sestica++;
        }
        if(kms[z]=='7'){
            brainrot_factor+=broj_sestica;
        }
    }
    
    return brainrot_factor;
}


int main()
{
    int n,q;
    cin>>n>>q;
    string mozgotrul;
    cin>>mozgotrul;
    for(int i=0;i<q;i++){
        int levi,desni;
        cin>>levi>>desni;
        levi--;
        string radni="";
        for(int j=levi;j<desni;j++){
            radni.push_back(mozgotrul[j]);
        }
        if(radni.find('?')>radni.size()){
            cout<<brainrot_counter_kms(radni);
        }
        else if(radni.find('6')>radni.size() && radni.find('7')>radni.size()){
            int d=radni.size();
            cout<<(d/2)*(d-(d/2));
        }
    }
}