#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int l = (int)s.size();
  vector<int> v(l);
  for (int i = 0; i < l - 1; ++i) {
    if (i > 0)
      v[i] = v[i - 1];
    else
      v[i] = 0;
    if (s[i] == s[i + 1]) v[i] += 1;
  }
  int n;
  cin >> n;
  while (n--) {
    int a, b;
    cin >> a >> b;
    int r = v[b - 2];
    if (a > 1) r -= v[a - 2];
    cout << r << "\n";
  }
  return 0;
}
