#include <bits/stdc++.h>
using namespace std;
char a[1000000];
int x[1000000], i, j, l, r;
int main() {
  cin >> a;
  int len = strlen(a);
  x[0] = 0;
  for (i = 1; i < len; i++) {
    if (a[i - 1] == a[i]) {
      x[i] += x[i - 1] + 1;
    } else
      x[i] = x[i - 1];
  }
  cin >> j;
  for (i = 0; i < j; i++) {
    cin >> l >> r;
    cout << x[r - 1] - x[l - 1] << "\n";
  }
  return 0;
}
