#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int psum[100010];
  string before = s.substr(0, 1);
  psum[0] = 0;
  psum[1] = 0;
  for (int i = 1; i < s.length(); i++) {
    psum[i + 1] = psum[i];
    if (before[0] == s[i]) {
      psum[i + 1]++;
    } else {
      before = s[i];
    }
  }
  int t;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    int a, b;
    cin >> a >> b;
    cout << psum[b] - psum[a] << "\n";
  }
  return 0;
}
