#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  int q;
  cin >> q;
  int dp[100002];
  dp[0] = 0;
  for (int i = 1; i < s.size(); ++i) {
    if (s[i] == s[i - 1]) {
      dp[i] = dp[i - 1] + 1;
    } else {
      dp[i] = dp[i - 1];
    }
  }
  int x, y;
  while (q--) {
    cin >> x >> y;
    cout << dp[y - 1] - dp[x - 1] << endl;
  }
  return 0;
}
