#include <bits/stdc++.h>
using namespace std;
int arr[200000];
int main() {
  string str;
  cin >> str;
  int cont = 0;
  for (int i = 0; i < str.size() - 1; i++) {
    if (str[i] == str[i + 1]) {
      cont++;
      arr[i + 1] = cont;
    } else {
      arr[i + 1] = cont;
    }
  }
  arr[str.size()] = arr[str.size() - 1];
  int n;
  scanf("%d", &n);
  for (int k = 0; k < n; k++) {
    int l, r;
    scanf("%d%d", &l, &r);
    int total = (arr[l] - arr[l - 1]) + (arr[r - 1] - arr[l]);
    printf("%d\n", total);
  }
  return 0;
}
