#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int m, l[100010], r[100010], a[200010], n = s.end() - s.begin();
  cin >> m;
  for (int i = 0; i < n; ++i) {
    if (s[i] == s[i + 1])
      a[i] = 1;
    else
      a[i] = 0;
  }
  for (int i = 1; i <= n; ++i) a[i] += a[i - 1];
  for (int i = 0; i < m; ++i) {
    cin >> l[i] >> r[i];
    cout << a[r[i] - 2] - a[l[i] - 2] << endl;
  }
}
