#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int n, a, b;
  int cn;
  cin >> s;
  int howmany = s.length();
  int ar[howmany];
  int kiek = 0;
  for (int q = 0; q < howmany; q++) {
    if (q == 0) {
      ar[q] = 0;
    } else {
      if (howmany != q) {
        if (s[q] == s[q - 1]) {
          kiek++;
        }
      }
    }
    ar[q] = kiek;
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    cin >> b;
    int res;
    res = ar[b - 1] - ar[a - 1];
    cout << res << endl;
  }
  return 0;
}
