#include <bits/stdc++.h>
using namespace std;
string s;
int dp[1 << 18], n, q;
int main() {
  cin >> s;
  n = s.size();
  s = '0' + s;
  for (int i = 1; i <= n; i++) dp[i] = dp[i - 1] + (s[i] == s[i - 1]);
  scanf("%d\n", &q);
  for (; q > 0; q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", dp[r] - dp[l]);
  }
  return 0;
}
