#include <bits/stdc++.h>
using namespace std;
char s[100005];
int d[100005];
int main() {
  while (cin >> s) {
    memset(d, 0, sizeof(d));
    int n = strlen(s);
    for (int i = 0; i < n; i++) {
      d[i + 1] = d[i];
      if (s[i] == s[i + 1]) d[i + 1] += 1;
    }
    int m;
    cin >> m;
    while (m--) {
      int x, y;
      scanf("%d%d", &x, &y);
      cout << d[y - 1] - d[x - 1] << endl;
    }
  }
}
