#include <bits/stdc++.h>
using namespace std;
int ans[100005];
int main() {
  string _string;
  while (cin >> _string) {
    memset(ans, 0, sizeof(ans));
    int length = _string.length();
    for (int i = 1; i < length; ++i) {
      if (_string.at(i - 1) == _string.at(i))
        ans[i] = ans[i - 1] + 1;
      else
        ans[i] = ans[i - 1];
    }
    int m, x, y;
    cin >> m;
    for (int i = 0; i < m; ++i) {
      cin >> x >> y;
      cout << ans[y - 1] - ans[x - 1] << endl;
    }
  }
  return 0;
}
