#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  string str;
  cin >> str;
  int n = str.length();
  vector<int> V(n);
  if (str[0] == str[1])
    V[0] = 1;
  else
    V[0] = 0;
  for (int i = 1; i < n - 1; i++) {
    if (str[i] == str[i + 1])
      V[i] = V[i - 1] + 1;
    else
      V[i] = V[i - 1];
  }
  int t;
  cin >> t;
  while (t--) {
    int l, r;
    cin >> l >> r;
    int res;
    l--;
    r--;
    if (l != 0)
      res = V[r - 1] - V[l - 1];
    else
      res = V[r - 1];
    cout << res << "\n";
  }
}
