#include <bits/stdc++.h>
using namespace std;
int ca[100005];
int main() {
  char ia[100005];
  cin >> ia;
  for (int i = 0; i < strlen(ia) - 1; i++) {
    if (ia[i] == ia[i + 1])
      ca[i + 1] = ca[i] + 1;
    else
      ca[i + 1] = ca[i];
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    cout << (ca[b - 1] - ca[a - 1]) << endl;
  }
}
