#include <iostream>

using namespace std;

int main()
{
    int n,q;
    cin>>n>>q;
    string a;
    cin>>a;
    int qodg[q];
    int qbr=0;
    if (a[0]=='?')
    {
        for (int i=0;i<q;i++)
        {
            int l,r;
            cin>>l>>r;
            int x=r-l+1;
            if (x%2==0)
                qodg[qbr++]=(x/2)*(x/2)<<'\n';
            else
                qodg[qbr++]=((x-1)/2)*((x+1)/2)<<'\n';
        }
        for (int i=0;i<q;i++)
        {
            cout<<qodg[i]<<endl;
        }
    }
    else
    {
        for (int i=0;i<q;i++)
        {
            int l,r;
            cin>>l>>r;
            int br=0;
            for (int j=l-1;j<r;j++)
            {
                for (int k=j+1;k<r;k++)
                {
                    if (a[j]=='6' && a[k]=='7')
                        br++;
                }
            }
            qodg[qbr++]=br;
        }
        for (int i=0;i<q;i++)
        {
            cout<<qodg[i]<<endl;
        }
    }
}