#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long a, f, sec, t = 0, h = 0;     cin >> a;     vector<long long> par;     vector<long long> m;     for (int i = 0; i < s.length(); i++) {       if (s[i - 1] == s[i]) {         h++;       }       par.push_back(h);     }     for (int i = 0; i < a; i++) {       cin >> f >> sec;       m.push_back(par[sec - 1] - par[f - 1]);     }     for (int i = 0; i < a; i++) {       cout << m[i] << endl;     }   }   