#include <bits/stdc++.h>
using namespace std;
int freq[100005], cum[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string str;
  cin >> str;
  int n;
  cin >> n;
  for (int i = 0; i < str.size() - 1; i++) {
    if (str[i] == str[i + 1]) freq[i + 1] = 1;
  }
  for (int i = 0; i <= str.size(); i++) {
    if (i == 0)
      cum[i] = freq[i];
    else
      cum[i] = cum[i - 1] + freq[i];
  }
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    cout << cum[r - 1] - cum[l - 1] << "\n";
  }
  return 0;
}
