#include <bits/stdc++.h>
using namespace std;
string s;
int n, a, b;
int v[100009] = {0};
int out[100009];
int main() {
  cin >> s;
  cin >> n;
  for (int i = 0; i < (int)s.length(); i++)
    if (s[i] == s[i + 1]) v[i + 1] = 1;
  for (int i = 1; i < (int)s.length(); i++) v[i] += v[i - 1];
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    out[i] = v[b - 1] - v[a - 1];
  }
  for (int i = 0; i < n; i++) cout << out[i] << "\n";
  return 0;
}
