#include <bits/stdc++.h>
using namespace std;
int kol[100005];
int main() {
  ios_base::sync_with_stdio(false);
  string a;
  cin >> a;
  for (int i = 0; i < a.size() - 1; i++) {
    if (a[i] == a[i + 1])
      kol[i + 1] = 1 + kol[i];
    else
      kol[i + 1] += kol[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    cout << kol[r - 1] - kol[l - 1] << endl;
  }
}
