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