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