#include <bits/stdc++.h>
using namespace std;
int a[100000];
int main() {
  string s;
  cin >> s;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1]) a[i - 1]++;
  }
  for (int i = 0; i < s.size() - 1; i++) {
    a[i + 1] += a[i];
  }
  int n;
  cin >> n;
  while (n--) {
    int x, y;
    cin >> x >> y;
    cout << (y - 2 >= 0 ? a[y - 2] : 0) - (x - 2 >= 0 ? a[x - 2] : 0) << "\n";
  }
  return 0;
}
