#include <bits/stdc++.h>
using namespace std;
long long m, n, x, y, t;
long long sum = 0;
const int ma = 500500;
long long dp[ma], a[ma], b[ma], c[ma];
int main() {
  string s;
  cin >> s;
  memset(dp, 0, sizeof dp);
  for (int i = 0; i < s.size() - 1; i++) {
    if (i != 0) dp[i] = dp[i - 1];
    if (s[i] == s[i + 1]) {
      dp[i]++;
    }
  }
  cin >> m;
  for (long long int i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    x--;
    y--;
    cout << dp[y - 1] - dp[x - 1] << endl;
  }
  return 0;
}
