#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 6;
int32_t main(int argc, char* argv[]) {
  string s;
  cin >> s;
  int n = s.length();
  int dp[n + 1];
  dp[0] = 0;
  for (int i = 1; i < n; i++) {
    if (s[i - 1] == s[i])
      dp[i] = dp[i - 1] + 1;
    else
      dp[i] = dp[i - 1];
  }
  dp[n] = dp[n - 1];
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    cout << dp[v - 1] - dp[u - 1] << endl;
  }
}
