#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int m, n, x, y;
  string s;
  cin >> s;
  n = s.length();
  int a[n];
  for (int i = 0; i < n; i++) {
    if (s[i] == s[i - 1] && i > 0) {
      a[i] = 1;
    } else {
      a[i] = 0;
    }
  }
  for (int i = 1; i < n; i++) {
    a[i] += a[i - 1];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    cout << a[y - 1] - a[x - 1] << "\n";
  }
  return 0;
}
