#include <bits/stdc++.h>
using namespace std;
char s[100020];
int sum[100020];
int main() {
  while (~scanf("%s", s + 1)) {
    int len = strlen(s + 1);
    sum[0] = 0;
    for (int i = 1; i <= len; i++)
      sum[i] = sum[i - 1] + (s[i] == s[i + 1] ? 1 : 0);
    int t;
    cin >> t;
    while (t--) {
      int w, l, r;
      cin >> l >> r;
      w = sum[r - 1] - sum[l - 1];
      cout << w << endl;
    }
  }
}
