#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int m;
  int a[100005] = {0};
  int b[100005] = {0};
  cin >> s;
  s = " " + s;
  cin >> m;
  for (int i = 1; i <= s.length(); i++) {
    if (s[i] == s[i + 1]) a[i] = 1;
  }
  for (int i = 1; i <= s.length(); i++) {
    b[i] = b[i - 1] + a[i];
  }
  while (m--) {
    int l, r, flag = 0;
    cin >> l >> r;
    flag = b[r - 1] - b[l - 1];
    cout << flag << endl;
  }
  return 0;
}
