#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;
    while (q--) {
        // setup
        int l, r;
        cin >> l >> r;
        sestsedam67 = "";
        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;
        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;
            }
        }
        
        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';

        }
        cout << br67;
    }
    return 0;
}