#include <bits/stdc++.h>
using namespace std;
string s;
long long int n, m, i, j, x, y, a[200000];
pair<long long int, long long int> p[200000];
int main() {
  cin >> s >> m;
  n = s.size();
  a[0] = 0;
  j = 1;
  for (i = 0; i < n; i++) {
    if (s[i] == s[i + 1]) {
      a[j] = a[j - 1] + 1;
    } else {
      a[j] = a[j - 1];
    }
    j++;
  }
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    p[i].first = x;
    p[i].second = y;
  }
  x = y = 0;
  for (i = 0; i < m; i++) {
    x = p[i].first;
    y = p[i].second;
    cout << abs(a[x - 1] - a[y - 1]) << endl;
  }
  return 0;
}
