#include <bits/stdc++.h>
using namespace std;
int a[100020];
int main() {
  string str;
  cin >> str;
  int i;
  a[0] = 0;
  char c = str[0];
  for (i = 1; i < str.length(); i++) {
    if (str[i] == c)
      a[i] = a[i - 1] + 1;
    else
      a[i] = a[i - 1], c = str[i];
  }
  int m;
  cin >> m;
  for (i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    cout << a[r - 1] - a[l - 1] << endl;
  }
  return 0;
}
