Problem: Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.

You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Each query is described by a pair of integers li, ri (1 ≤ li < ri ≤ n). The answer to the query li, ri is the number of such integers i (li ≤ i < ri), that si = si + 1.

Ilya the Lion wants to help his friends but is there anyone to help him? Help Ilya, solve the problem.

Input

The first line contains string s of length n (2 ≤ n ≤ 105). It is guaranteed that the given string only consists of characters "." and "#".

The next line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains the description of the corresponding query. The i-th line contains integers li, ri (1 ≤ li < ri ≤ n).

Output

Print m integers — the answers to the queries in the order in which they are given in the input.

Examples

Input

......
4
3 4
2 3
1 6
2 6


Output

1
1
5
4


Input

#..###
5
1 3
5 6
1 5
3 6
3 4


Output

1
1
2
2
0

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
long long int n, q;
long long int gcd(long long int a, long long int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long int powe(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      res = (res * a);
    }
    a = (a * a);
    b /= 2;
  }
  return res;
}
long long int power(long long int a, long long int b, long long int M) {
  a %= M;
  long long int res = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      res = (res * a) % M;
    }
    a = (a * a) % M;
    b /= 2;
  }
  return res;
}
long long int extendedEuclid(long long int A, long long int B, long long int &x,
                             long long int &y) {
  if (B == 0) {
    x = 1;
    y = 0;
    return A;
  } else {
    long long int x1, y1;
    long long int gcd = extendedEuclid(B, A % B, x1, y1);
    y = x1 - (A / B) * y1;
    x = y1;
    return gcd;
  }
}
long long int mi(long long int A, long long int M) {
  long long int x, y;
  extendedEuclid(A, M, x, y);
  if (x < 0) {
    x += (long long int)1000000007;
  }
  return x;
}
template <typename T>
void read(T &x) {
  cin >> x;
}
template <typename T, typename T0>
void read(T &x, T0 &y) {
  cin >> x >> y;
}
template <typename T, typename T0, typename T1>
void read(T &x, T0 &y, T1 &z) {
  cin >> x >> y >> z;
}
template <typename T, typename T0, typename T1, typename T2>
void read(T &x, T0 &y, T1 &z, T2 &w) {
  cin >> x >> y >> z >> w;
}
template <typename T, typename T0>
void read(pair<T, T0> &p) {
  cin >> p.first >> p.second;
}
template <typename T, typename T0>
void write(pair<T, T0> &p) {
  write(p.first);
  write(p.second);
}
template <typename T>
void read(vector<T> &oneD, long long int n) {
  for (long long int i = 0; i < n; i++) {
    long long int x;
    read(x);
    oneD.push_back(x);
  }
}
template <typename T>
void read(T oneD[], long long int n) {
  for (long long int i = 0; i < n; i++) {
    read(oneD[i]);
  }
}
template <typename T>
void write(T oneD[], int n) {
  for (long long int i = 0; i < n; i++) {
    write(oneD[i]);
  }
  cout << endl;
}
vector<bool> sieve(1000000, true);
void Sieve() {
  sieve[0] = false;
  sieve[1] = false;
  for (long long int i = 2; i * i <= 1000000; i++) {
    if (sieve[i] == true) {
      for (long long int j = i * i; j < 1000000; j += i) sieve[j] = false;
    }
  }
}
vector<long long int> sieve_spf;
void Sieve_spf() {
  const long long int n = 1e6 + 5;
  sieve_spf.resize(n);
  for (long long int i = 0; i < n; i++) sieve_spf[i] = i;
  sieve_spf[0] = -1;
  sieve_spf[1] = 1;
  for (long long int i = 2; i <= n; i += 2) sieve_spf[i] = 2;
  for (long long int i = 3; i <= n; i += 2)
    if (sieve_spf[i] == i)
      for (long long int j = i * i; j <= n; j += i)
        if (sieve_spf[j] == j) sieve_spf[j] = i;
}
bool oppositeSigns(long long int x, long long int y) { return ((x ^ y) < 0); }
int mpt(long long int n) {
  long long int c = 0;
  long long int n1 = pow(2, c);
  while (n1 < n) {
    c++;
    n1 = pow(2, c);
  }
  return c;
}
void the_happiest_place_on_earth() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
}
const int N = 200023;
long long int dp[N] = {0};
void solve() {
  string second;
  read(second);
  n = second.size();
  second = 'k' + second;
  for (long long int i = 1; i <= n; i++) {
    if (second[i] == second[i - 1]) dp[i]++;
    dp[i] += dp[i - 1];
  }
  return;
}
int main() {
  the_happiest_place_on_earth();
  solve();
  q = 1;
  read(q);
  while (q--) {
    long long int a, b;
    read(a, b);
    cout << dp[b] - dp[a] << "\n";
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}