#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int m, count[100005] = {0}, countx = 0;
  cin >> m;
  int a[m], b[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1]) {
      countx++;
    }
    count[i] = countx;
  }
  for (int i = 0; i < m; i++) {
    cout << count[b[i] - 1] - count[a[i] - 1] << "\n";
  }
}
