#include <bits/stdc++.h>
#include <cstring>
using namespace std;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    string n;
    cin>>n;
    long p;
    cin >>p;
    for(int i; i<p; i++){
        int l, r;
        cin >> l>>r;
        string m;
        m = n.substr(l-1, m.size()-l+1+r-m.size());
        string p1 = "cl";
        char p2 = p1[0];
        int slov = 0;
        int qws = p1[0];
        for(int y = 0; y<m.size(); y++){
            int qwf = m[y];
            
            cout << qwf << " " << qws<< "\n";
            if(qwf<qws){
                slov+=1;
            }
            qws = m[y];
        }
        cout << slov << "\n";
    }

}