#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, a, b;
  string s;
  cin >> s;
  int l = s.length();
  int dp[l];
  dp[0] = 0;
  for (int i = 1; i < l; i++) {
    dp[i] = dp[i - 1];
    if (s[i] == s[i - 1]) dp[i]++;
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    printf("%d\n", dp[b - 1] - dp[a - 1]);
  }
}
