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