#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;

    for(int i = 0; i < q; i++)
    {
        int l, r;
        cin >> l >> r;

        if(count(s.begin(), s.end(), '?') == s.size())
        {
            long long a = (r - l + 1) / 2;
            long long b = (r - l + 1) - a;

            cout << a * b << endl;
        }
        else if(count(s.begin(), s.end(), '?') == 0)
        {
            int ans = 0;
            int t = count(s.begin() + l - 1, s.begin() + r, '7');
            cout << t << endl;

            for(int i = l - 1; i < r; i++)
            {
                if(s[i] == '7') t--;
                else ans += t;

                cout << ans << " " << t << endl;
            }

            cout << ans;
        }
    }

    return 0;
}