#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int m;
  cin >> s;
  int n = s.length();
  vector<int> count[n];
  int k;
  for (int i = 0; i < 1; i++) {
    count[i].push_back(0);
    for (int j = i + 1, k = 1; j < n; j++, k++) {
      count[i].push_back(s[j - 1] == s[j] ? 1 + count[i][k - 1]
                                          : count[i][k - 1]);
    }
  }
  cin >> m;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    cout << count[0][b] - count[0][a] << endl;
  }
  return 0;
}
