#include <bits/stdc++.h>
using namespace std;
string s;
int m, a, b, cou;
int main() {
  cin >> s;
  vector<int> x(s.size());
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == s[i + 1]) cou++;
    x[i + 1] = cou;
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    printf("%d\n", x[b - 1] - x[a - 1]);
  }
  return 0;
}
