#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    string s;
    cin >> s;
    vector<int> v;
    v.push_back(0);
    int n = s.length();
    for (int i = 1; i < n; i++) {
      v.push_back(v[i - 1]);
      if (s[i] == s[i - 1]) v[i]++;
    }
    int m;
    cin >> m;
    while (m--) {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      cout << v[r] - v[l] << endl;
    }
  }
  return 0;
}
