#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  const int n = s.length() + 5;
  int arr[n];
  memset(arr, 0, sizeof arr);
  int m, l, r;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == s[i + 1]) {
      arr[i + 2]++;
    }
    arr[i + 1] += arr[i];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    cout << arr[r] - arr[l] << "\n";
  }
}
