#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size(), i;
  int ps[n + 1];
  ps[0] = 0;
  for (i = 1; i <= n; i++) {
    ps[i] = ps[i - 1];
    if (s[i] == s[i - 1]) ps[i]++;
  }
  int q;
  cin >> q;
  for (i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    cout << ps[r - 1] - ps[l - 1] << endl;
  }
}
