#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve()
{
    ll n,q;
    cin >> n >> q;
    vector<ll> a(n);
    //for(int i = 0; i < n; i++)cin >> a[i];
    string s;
    cin >> s;
    vector<ll> pref6(n,0),pref7(n,0),prefu(n,0);
    if(s[0]=='6'){
        pref6[0] = 1;
        pref7 [0] = 0;
        prefu[0] = 0;
    }
    if(s[0]=='7'){
        pref6[0] = 0;
        pref7 [0] = 1;
        prefu[0] = 0;
    }
    if(s[0]=='7'){
        pref6[0] = 0;
        pref7 [0] = 0;
        prefu[0] = 1;
    }



    for(int i = 1; i < n; i++){
        pref6[i] = pref6[i-1] + ll(s[i]=='6');
        pref7[i] = pref7[i-1] + ll(s[i]=='7');
        prefu[i] = prefu[i-1] + ll(s[i]=='?');
    }

    for(int  i = 0; i < n; i++){
        cout << pref6[i] << " ";
    }
    cout << "\n";

    for(int  i = 0; i < n; i++){
        cout << pref7[i] << " ";
    }
    cout << "\n";

    for(int  i = 0; i < n; i++){
        cout << prefu[i] << " ";
    }
    cout << "\n";

    while(q--){

        int l,r;
        cin >> l >> r;
        l--;r--;

        ll cnt6 = pref6[r] - pref6[l-1];
        ll cnt7 = pref7[r] - pref7[l-1];
        ll cntu = prefu[r] - prefu[l-1];



        if(l==0){
            cnt6 = pref6[r];
            cnt7 = pref7[r];
            cntu = prefu[r];
        }

        ll mn = min(cnt6,cnt7);
        ll mx = max(cnt6,cnt7);

        ll dif = mx-mn;
        if(cntu >= dif){
            cntu-=dif;
        }
        mn+= cntu/2;
        mx+=cntu/2 + cntu%2;
        cout << mn*mx << "\n";



    }




}

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