#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.length();
  vector<int> pref(n);
  if (s[0] == s[1])
    pref[0] = 1;
  else
    pref[0] = 0;
  for (int i = 1; i < n - 1; i++) {
    if (s[i] == s[i + 1])
      pref[i] = pref[i - 1] + 1;
    else
      pref[i] = pref[i - 1];
  }
  pref[n - 1] = pref[n - 2];
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    if (l == 0) {
      cout << pref[r - 1] << endl;
    } else {
      cout << pref[r - 1] - pref[l - 1] << endl;
    }
  }
  return 0;
}
