#include <bits/stdc++.h>
using namespace std;
const int N = 111111;
char ch[N];
int sum[N];
int main() {
  int n, l, r, len;
  while (cin >> ch + 1) {
    scanf("%d", &n);
    sum[0] = 0;
    len = strlen(ch + 1);
    for (int i = 1; i < len; i++)
      if (ch[i] == ch[i + 1])
        sum[i] = sum[i - 1] + 1;
      else
        sum[i] = sum[i - 1];
    while (n--) {
      scanf("%d%d", &l, &r);
      printf("%d\n", sum[r - 1] - sum[l - 1]);
    }
  }
}
