#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int dx[] = {-1, 1, 0, 0, -1, 1, -1, 1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
long long gcd(long long x, long long y) {
  if (!y) return x;
  return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return (x / gcd(x, y)) * y; }
long long fastpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b % 2) res *= a;
    b /= 2, a *= a;
  }
  return res;
}
bool isprime(long long n) {
  if (n == 1 || n == 0) return 0;
  for (int i = 2; i <= sqrt(n); i++)
    if (n % i == 0) return 0;
  return 1;
}
long long ceilval(long long a, long long b) { return (a / b) + ((a % b) != 0); }
bool getbit(int num, int index) { return (num & (1 << index)); }
bool is_pow_of_two(int num) { return !(num & (num - 1)); }
void solve() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> arr(n + 1);
  for (int i = 0; i < n; i++) {
    if (s[i] == s[i + 1]) arr[i + 1] = 1;
  }
  for (int i = 2; i <= n; i++) arr[i] = arr[i - 1] + arr[i];
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    cout << arr[b - 1] - arr[a - 1] << "\n";
  }
}
int main() {
  fast();
  solve();
}
