#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int q, a[1000000], b, c, i;
  string s;
  cin >> s;
  a[0] = 0;
  for (i = 1; i < s.size(); i++) {
    if (s[i - 1] == s[i]) {
      a[i] = a[i - 1] + 1;
    } else
      a[i] = a[i - 1];
  }
  cin >> q;
  while (q--) {
    c = 0;
    cin >> c >> b;
    cout << abs(a[c - 1] - a[b - 1]) << endl;
  }
}
