#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int i, n = s.length();
  int dp[n];
  dp[0] = 0;
  for (i = 1; i < s.length(); i++) {
    if (s[i - 1] == s[i])
      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--;
    r--;
    cout << dp[r] - dp[l] << endl;
  }
}
