#include <bits/stdc++.h>
using namespace std;
vector<int> pre;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int m;
  cin >> m;
  pre.push_back(0);
  pre.push_back(s[0] == s[1]);
  for (int i = 2; i < (int)s.size(); i++)
    pre.push_back(pre[i - 1] + (s[i] == s[i - 1]));
  while (m--) {
    int l, r;
    cin >> l >> r;
    cout << pre[r - 1] - pre[l - 1] << "\n";
  }
}
