#include <bits/stdc++.h>
using namespace std;
int dp[100009];
int main() {
  string str;
  cin >> str;
  int length = str.length();
  for (int i = 0; i <= length - 2; i++) {
    dp[i + 1] = dp[i];
    if (str[i] == str[i + 1]) {
      dp[i + 1]++;
    }
  }
  int m;
  cin >> m;
  int l[m], r[m];
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i];
  }
  for (int i = 0; i < m; i++) {
    cout << dp[r[i] - 1] - dp[l[i] - 1] << endl;
  }
}
