#include <bits/stdc++.h>
int main() {
  long long int l, m, i, j = 0;
  char str[100001];
  scanf("%s", str);
  l = strlen(str);
  scanf("%lld", &m);
  long long int arr[m][2], arr1[l + 1];
  for (i = 0; i < m; i++) {
    scanf("%lld %lld", &arr[i][0], &arr[i][1]);
  }
  arr1[0] = 0;
  for (i = 0; i < l - 1; i++) {
    arr1[i + 1] = j;
    if (str[i] == str[i + 1]) {
      j++;
    }
  }
  arr1[l] = j;
  for (i = 0; i < m; i++) {
    printf("%lld\n", arr1[arr[i][1]] - arr1[arr[i][0]]);
  }
  return 0;
}
