#include <bits/stdc++.h>
using namespace std;
int main() {
  string x;
  int m, n, i, j, q;
  cin >> x;
  int len = x.length();
  int dp[len + 1];
  dp[1] = 0;
  for (i = 2; i <= len; i++) {
    if (x[i - 1] == x[i - 2])
      dp[i] = 1 + dp[i - 1];
    else
      dp[i] = dp[i - 1];
  }
  cin >> q;
  while (q--) {
    cin >> m >> n;
    cout << dp[n] - dp[m] << "\n";
  }
}
