#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[100000];
  string s;
  cin >> s;
  int n;
  cin >> n;
  if (s[0] == s[1])
    a[0] = 1;
  else
    a[0] = 0;
  for (int i = 1; i < s.length(); i++) {
    a[i] = a[i - 1];
    if (s[i] == s[i + 1]) a[i]++;
  }
  int m, k;
  for (int i = 0; i < n; i++) {
    cin >> m >> k;
    if (m == 1)
      cout << a[k - 2] << endl;
    else
      cout << a[k - 2] - a[m - 2] << endl;
  }
  return 0;
}
