#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int q, k = 1, sum = 0, len, i, l, r, c = 0, f = 0;
  cin >> s;
  len = s.size();
  int a[len + 10], b[len + 10];
  for (i = 0; i < len - 1; i++) {
    if (s[i] == s[i + 1]) {
      a[k] = 1;
      k++;
    } else {
      a[k] = 0;
      k++;
    }
  }
  b[1] = a[1];
  for (i = 2; i < k; i++) {
    b[i] = b[i - 1] + a[i];
  }
  for (i = 0; i < len - 1; i++) {
    if (s[i] == s[i + 1])
      c++;
    else
      break;
  }
  if (c == len - 1) f = 1;
  cin >> q;
  while (q--) {
    cin >> l >> r;
    if (f == 1) {
      cout << abs(l - r) << endl;
    } else {
      r = r - 1;
      if (l == r)
        cout << a[l] << endl;
      else if (l != 1) {
        sum = b[r] - b[l - 1];
        cout << sum << endl;
      } else {
        cout << b[r] << endl;
      }
    }
  }
  return 0;
}
