#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  int n = s.length();
  vector<int> dp(n + 1);
  for (int i = 1; i < n; i++) {
    if (s[i] == s[i - 1])
      dp[i] = dp[i - 1] + 1;
    else
      dp[i] = dp[i - 1];
  }
  int m;
  cin >> m;
  while (m--) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    cout << dp[y] - dp[x] << "\n";
  }
  return 0;
}
