#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  map<int, int> mp;
  for (int i = 1; i <= s.length() - 1; i++) {
    if (s[i - 1] == s[i]) mp[i]++;
    mp[i] += mp[i - 1];
  }
  while (q--) {
    int l, r;
    cin >> l >> r;
    int ans = mp[r - 1] - mp[l - 1];
    cout << ans << "\n";
  }
}
