#include <bits/stdc++.h>

using namespace std;


// SEST SEDAM

int main()
{
    iostream::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n, q;
    cin >> n >> q;
    string sestsedam, sestsedam67;
    cin >> sestsedam;
    bool pitanja = true;
    for (int i = 0; i < n; i++) {
        if (sestsedam[i] != '?') {
            pitanja = false;
            break;
        }
    }
    while (q--) {
        // setup
        int l, r;
        cin >> l >> r;
        sestsedam67 = "";
        if (pitanja) {
            cout << (r - l + 1) / 2 + ((r - l + 1) - (r - l + 1) / 2) << "\n";
            continue;
        }
        for (int i = l - 1; i < r; i++) {
            sestsedam67.push_back(sestsedam[i]);
        }
       // cout << sestsedam67 << endl;

        // brojac 6 i 7
        int sest = 0, sedam = 0, znkpit = 0;
        int br67 = 0;
        for (int i = 0; i < r - l + 1; i++) {
            if (sestsedam67[i] == '6') sest++;
            else if (sestsedam67[i] == '7') {
                sedam++;
                br67 += sest;
            }
            else znkpit++;
        }

        if (sest + sedam == r - l + 1);

        // svi ?
        /*
        else if (sest == 0 && sedam == 0) {
            for (int i = 0; i < r - l + 1; i++) {
                if (i < n / 2) sest++;
                else sedam++;
                br67 = sest * sedam;
            }
        }*/

        else {
            if (sestsedam67[r - l] == '?') {sestsedam67[r - l] = '7'; sedam++; znkpit--;}
            int sest2 = 0;
            int sedam2 = sedam;
            int znkpit2 = 0;
            bool checkagain = false;

            for (int i = 0; i < r - l + 1 || checkagain; i++) {

                if (sestsedam67[i] == '6') sest2++;
                else if (sestsedam67[i] == '7') sedam2--;
                else {
                        //cout << sest2 << " * 6  " << sedam2 << " * 7   " << znkpit2 << " * ? (" << znkpit << ")  (za i = " << i << ")  ";
                    if (sest2 + znkpit2 <= sedam2) {sestsedam67[i] = '6'; sest2++; znkpit--;}
                    else if (sest2 >= sedam2 + znkpit - znkpit2) {sestsedam67[i] = '7'; znkpit--;}
                    else {
                        sestsedam67[i] = '6';
                        sest2++;
                        znkpit2++;
                        //checkagain = true;
                    }
                }
                if (checkagain && i == r - l + 2) {
                    i = 0;
                    checkagain = false;
                    sest2 = 0;
                    sedam2 = sedam;
                    znkpit2 = 0;
                }
            }
            //cout << sestsedam67 << "<-------      \n ";
            int sest3 = 0;
            int sedam3 = 0;
            br67 = 0;
            for (int i = 0; i < r - l + 1; i++) {
                if (sestsedam67[i] == '6') sest3++;
                else if (sestsedam67[i] == '7') {
                    sedam3++;
                    br67 += sest3;
                }
            }

        }
        cout << br67 << "\n";
    }
    return 0;
}