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