#include <bits/stdc++.h>
using namespace std;
int main() {
  int l, r;
  char s[100006];
  cin >> s;
  int len = strlen(s);
  int a[100006];
  memset(a, 0, sizeof(a));
  for (int i = 1; i < len; i++) {
    if (s[i] == s[i - 1])
      a[i] = a[i - 1] + 1;
    else
      a[i] = a[i - 1];
  }
  int n;
  cin >> n;
  while (n--) {
    cin >> l >> r;
    cout << a[r - 1] - a[l - 1] << endl;
  }
}
