#include <bits/stdc++.h>
using namespace std;
const int mxN = 2e5;
int n, a[mxN], k;
void solve() {
  string s;
  cin >> s;
  vector<long long> arr;
  long long k = 0;
  for (int i = 1; i < s.size(); ++i) {
    if (s[i] == s[i - 1]) {
      k += 1;
    }
    arr.emplace_back(k);
  }
  long long n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    long long l, r;
    cin >> l >> r;
    if (l == 1) {
      cout << arr[r - 2] << endl;
    } else {
      cout << abs(arr[r - 2] - arr[l - 2]) << endl;
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
