#include <bits/stdc++.h>
const int MXN = 1e6 + 1;
const int INF = 1e9 + 7;
const int N = 1e3 + 1;
using namespace std;
string s;
long long int n, l, r, dp[MXN];
int main() {
  ios_base ::sync_with_stdio(0);
  cin >> s;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1]) {
      dp[i] = dp[i - 1] + 1;
    } else {
      dp[i] = dp[i - 1];
    }
  }
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> l >> r;
    cout << dp[r - 1] - dp[l - 1] << endl;
    ;
  }
  return 0;
}
