#include <bits/stdc++.h>
using namespace std;
template <class T>
T max(T a, T b, T c) {
  return ((a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c));
}
template <class T>
T min(T a, T b, T c) {
  return ((a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c));
}
const int MOD = 1000000000 + 7;
const int MAXN = 100000 + 9;
int main() {
  int t = 1;
  while (t--) {
    string str;
    cin >> str;
    int n = str.length();
    int m;
    cin >> m;
    vector<int> dp(n);
    for (int i = 1; i < n; i++) {
      dp[i] = dp[i - 1] + (str[i] == str[i - 1] ? 1 : 0);
    }
    while (m--) {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      cout << dp[r] - dp[l] << "\n";
    }
  }
  return 0;
}
