#include <bits/stdc++.h>
using namespace std;
vector<int> build_dict(const string &s) {
  vector<int> d(s.size(), 0);
  for (size_t i = 1; i < d.size(); ++i) {
    d[i] = d[i - 1];
    if (s[i - 1] == s[i]) d[i]++;
  }
  return d;
}
int main() {
  string s;
  cin >> s;
  vector<int> d = build_dict(s);
  int query_num;
  cin >> query_num;
  for (int i = 0; i < query_num; ++i) {
    int p, q;
    cin >> p >> q;
    cout << d[q - 1] - d[p - 1] << endl;
  }
  return 0;
}
