#include <bits/stdc++.h>
using namespace std;
char s[100001];
int dp[100001];
int main() {
  cin >> s;
  dp[0] = 0;
  int i = 1;
  while (s[i]) {
    dp[i] = (s[i] == s[i - 1]) ? dp[i - 1] + 1 : dp[i - 1];
    ++i;
  }
  int q;
  cin >> q;
  vector<int> ans;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    ans.push_back(dp[r - 1] - dp[l - 1]);
  }
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i] << "\n";
  }
  return 0;
}
