#include <bits/stdc++.h>
const long long maxn = 100005;
const double pi = acos(-1);
using namespace std;
int dp[maxn] = {0};
int main() {
  string s;
  cin >> s;
  int n = s.length();
  int t;
  cin >> t;
  if (s[0] == s[1]) {
    dp[0] = 1;
  }
  for (int i = 1; i < n - 1; i++) {
    if (s[i] == s[i + 1]) {
      dp[i] = dp[i - 1] + 1;
    } else {
      dp[i] = dp[i - 1];
    }
  }
  dp[n - 1] = dp[n - 2];
  for (int i = 0; i < n; i++) {
  }
  cout << endl;
  while (t--) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    cout << dp[l] - dp[l - 1] + dp[--r] - dp[l] << endl;
  }
  return 0;
}
