#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(vector<T> v) {
  for (T &i : v) cout << i << " ";
  cout << "\n";
}
template <typename T>
void read(vector<T> &v) {
  for (T &i : v) cin >> i;
}
long long mod = 1e9 + 7;
void solve() {
  string s;
  cin >> s;
  int n = s.length();
  int m;
  cin >> m;
  vector<int> v(n);
  for (int i = 0; i < n - 1; i++) {
    if (s[i] == s[i + 1]) {
      v[i] = 1;
    } else {
      v[i] = 0;
    }
  }
  for (int i = 1; i < n - 1; i++) {
    v[i] += v[i - 1];
  }
  v[n - 1] = v[n - 2];
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    if (x == 0)
      cout << v[y - 1] << "\n";
    else
      cout << v[y - 1] - v[x - 1] << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int tcs = 1;
  while (tcs--) solve();
  return 0;
}
