#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int* a = new int[s.length()];
  for (int i = 0; i < s.length(); i++) a[i] = 0;
  if (s.length() != 1) a[0] = (s[0] == s[1]);
  for (int i = 1; i + 1 < s.length(); i++) a[i] = a[i - 1] + (s[i] == s[i + 1]);
  if (s.length() != 1) a[s.length() - 1] = a[s.length() - 2];
  int k;
  cin >> k;
  int l, r;
  for (int i = 0; i < k; i++)
    cin >> l >> r, r--, l--,
        cout << a[r - 1] - ((l != 0) ? a[l - 1] : 0) << endl;
  return 0;
}
