#include <bits/stdc++.h>

using namespace std;

struct elem
{
    char v;
    int amt6=0;
};

void opt(elem &a,int l,int r)
{

}

int main()
{
    iostream::sync_with_stdio(false);
    int n,q;
    cin >> n >> q;
    elem a[n];
    bool prev6=false;
    bool blank=true;
    for(int i=0; i<n; i++)
    {
        char x;
        cin >> x;
        a[i].v=x;
        if(x!='?')blank=false;
        if(prev6)a[i].amt6=a[i-1].amt6++;
        else if(i!=0)a[i].amt6=a[i-1].amt6;


        if(x=='6')prev6=true;
        else prev6=false;
    }
    vector<int> res(q);
    for(int i=0; i<q; i++)
    {
        int l,r;
        cin >> l >> r;
        if(blank)
        {
            int m=r-l+1;
            res[i]=(m/2)*(m-m/2);
        }

    }

    for(auto c:res)cout << c << "\n";



    return 0;
}