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