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

int n, q, raz;
string s;
int levi[300005], desni[300005], psuma[300005], br[300005];
bool prvi = true, drugi = true;
void set1(){

    for(int i = 1; i <= q; i++){
        raz = desni[i] - levi[i] + 1;
        cout << raz << '\n';
        if((raz & 1) == 0){
            cout << (raz >> 1) * (raz >> 1) << '\n';
        }
        else{
            cout << ((raz >> 1)+ 1) * (raz >> 1) << '\n';
        }
    }
    return;
}
void set2(){
    if(s[1] == 6) br[1] = 1;
    for(int i = 0; i < n; i++){
        br[i] = br[i-1];
        psuma[i] = psuma[i-1];
        if(s[i] == '6'){
            br[i]++;
        }
        else{
            psuma[i] = psuma[i-1] + br[i];
        }
    }
    //for(int i = 0; i < n; i++){
    //    cout << psuma[i] << " " << br[i] << '\n';
    //}
    for(int i = 1; i <= q; i++){
        cout << psuma[desni[i]-1] << " " << psuma[levi[i]-2] << '\n';
        cout << psuma[desni[i]-1] - psuma[levi[i]-2] << '\n';
    }

}
int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n >> q;
    cin >> s;
    for(int i = 1; i <= q; i++){
        cin >> levi[i] >> desni[i];
    }
    for(int i = 0; i < n; i++){
        if(s[i] != '?'){
            prvi = false;
            break;
        }
    }
    for(int i = 0; i < n; i++){
        if(s[i] == '?'){
            drugi = false;
            break;
        }
    }
    if(prvi) set1();
    else if(drugi) set2();

    return 0;
}