#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  getline(cin, s);
  int arr[s.length()];
  int count = 0;
  for (int i = 0; i < s.length() - 1; i++) {
    if (s[i] == s[i + 1]) {
      count++;
    }
    arr[i] = count;
  }
  arr[s.length() - 1] = count;
  int m, l, r, res = 0;
  cin >> m;
  while (m--) {
    res = 0;
    cin >> l >> r;
    res = arr[r - 2] - arr[l - 1];
    if (s[l - 1] == s[l]) {
      res++;
    }
    cout << res << "\n";
  }
  return 0;
}
