#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  string S;
  int n;
  cin >> S >> n;
  vector<int> l(S.size(), 0);
  for (int i = 1; i < S.size(); i++) {
    if (S[i - 1] == S[i]) {
      l[i] = 1;
    }
  }
  for (int i = 1; i < S.size(); i++) {
    l[i] += l[i - 1];
  }
  for (int i = 0; i < n; i++) {
    int r1, l1;
    cin >> l1 >> r1;
    cout << l[r1 - 1] - (l1 == 1 ? 0 : l[l1 - 1]) << "\n";
  }
  return 0;
}
