#include <bits/stdc++.h>
using namespace std;
long long knitX[] = {+2, +2, -2, -2, +1, +1, -1, -1};
long long knitY[] = {+1, -1, +1, -1, +2, -2, +2, -2};
int main() {
  char s[1000007];
  while (scanf("%s", s) == 1) {
    int l = strlen(s);
    int dp[1000007];
    dp[1] = 0;
    for (int i = 2; i <= l; i++) {
      if (s[i - 1] == s[i - 2])
        dp[i] = dp[i - 1] + 1;
      else
        dp[i] = dp[i - 1];
    }
    int T, x, y;
    scanf("%d", &T);
    for (int tt = 1; tt <= T; tt++) {
      scanf("%d %d", &x, &y);
      printf("%d\n", dp[y] - dp[x]);
    }
  }
  return 0;
}
