#include <bits/stdc++.h>
int main() {
  char s[1000001];
  scanf("%s", s);
  int a[strlen(s) + 1];
  a[0] = 0;
  int count = 0;
  for (int i = 1; i < strlen(s); i++) {
    if (s[i] == s[i - 1]) {
      count++;
    }
    a[i] = count;
  }
  int t;
  scanf("%d", &t);
  while (t--) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", (a[r - 1] - a[l - 1]));
  }
  return 0;
}
