#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int l, c = 0, d = 0, r, m;
  string s;
  vector<long long int> v(101010, 0);
  cin >> s;
  cin >> m;
  for (int i = 1; i < s.length(); i++) {
    if (s[i] == s[i - 1])
      v[i] = v[i - 1] + 1;
    else
      v[i] = v[i - 1];
  }
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    cout << v[r - 1] - v[l - 1] << "\n";
  }
}
