#include <bits/stdc++.h>
using namespace std;
const int nax = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INTF = 2147483647;
const long long LLF = 9223372036854775807;
int dp[nax], pfs[nax];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  int n, l, r;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == s[i + 1]) {
      dp[i]++;
    }
  }
  for (int i = 1; i <= s.length(); i++) {
    pfs[i] = pfs[i - 1] + dp[i - 1];
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> l >> r;
    cout << pfs[r - 1] - pfs[l - 1] << "\n";
  }
  return 0;
}
