#include <bits/stdc++.h>
int main() {
  char ch[100005];
  long long int n, m, dp[100005], i, l, r;
  scanf("%s", ch);
  n = strlen(ch);
  if (ch[0] == ch[1]) dp[1] = 1;
  for (i = 1; i < n - 1; i++) {
    if (ch[i] == ch[i + 1])
      dp[i + 1] = dp[i] + 1;
    else
      dp[i + 1] = dp[i];
  }
  dp[n] = dp[n] + 1;
  scanf("%lld", &m);
  while (m--) {
    scanf("%lld %lld", &l, &r);
    l = l - 1;
    r = r - 1;
    printf("%lld\n", dp[r] - dp[l]);
  }
  return 0;
}
