#include <bits/stdc++.h>
 #define endl "\n"

using namespace std;

using ll = long long;
const ll inf =1e12;
void solve()
{
    ll n,q,i,br,res=0 ,oduz1,oduz2,l,r;
    string s;
    cin >> n >> q;
    cin >> s;
    vector<ll>pref6(n),suf7(n);
    for(i=0;i<n;i++)
    {
        pref6[i]=(s[i]=='6');

        if(i!=0)
        {
            pref6[i]+=pref6[i-1];

        }
    }
    for(i=n-1;i>=0;i--)
    {
        suf7[i]=(s[i]=='7');
        if(i!=n-1)
        {
            suf7[i]+=suf7[i+1];
        }
    }
    br=0;
    for(i=0;i<n;i++)
    {
        if(s[i]=='6')
        {
            br++;

        }
        else
        {
            res+=br;
        }
    }
  //  cout << res << endl;
    while(q--)
    {
        cin >> l >> r;
        l--;
        r--;
        oduz1=0;
        oduz2=0;
        if(l!=0)
        {
             oduz1=pref6[l-1]*suf7[l-1];
        //     cout << pref6[l-1] << " " << suf7[l-1] << endl;
        }
        if(r!=n-1)
        {
            ll oduzz=0;
            if(l!=0)
            {
                oduzz=pref6[l-1];
            }
            oduz2=suf7[r+1]*(pref6[r+1]-oduzz);
           //  cout << pref6[r+1] << " " << suf7[r+1] << endl;
        }
        cout << res-oduz1-oduz2 << endl;
    }

}



int main()
{
    ios_base::sync_with_stdio(false);
   cin.tie(NULL);
    ll t=1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
}