#include <bits/stdc++.h>
using namespace std;
int arr[100001];
int cum[100001];
int main() {
  string s;
  cin >> s;
  int ln = s.length();
  for (int i = 0; i <= ln - 2; i++)
    if (s[i] == s[i + 1]) arr[i] = 1;
  cum[0] = arr[0];
  for (int i = 0; i <= ln - 1; i++) cum[i] = cum[i - 1] + arr[i];
  int m;
  cin >> m;
  while (m--) {
    int l, r;
    scanf("%d%d", &l, &r);
    l--;
    r -= 2;
    if (l != 0)
      printf("%d\n", cum[r] - cum[l - 1]);
    else
      printf("%d\n", cum[r]);
  }
}
