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