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 JAVA):

Solution:

import java.util.*;
import java.io.*;
public class Main {
    public static boolean visited[];
    public static Integer distances[];
    public static void main ( String args[] ) {
        FastReader sc = new FastReader();
        String s = sc.nextLine();
        PrintWriter out = new PrintWriter(System.out);
        int equals []= new int [s.length()];
        if(s.charAt(0)==s.charAt(1))
            equals[0]= 1 ;
        else
            equals[0]= 0 ;
        for (int i = 1; i <s.length()-1 ; i++) {
            if(s.charAt(i)==s.charAt(i+1))
                equals[i]++;
            equals[i]+=equals[i-1];

        }
        equals[s.length()-1]= equals[s.length()-2];
       // System.out.println(Arrays.toString(equals));
        int q = sc.nextInt();
        while(q-->0){
            int l = sc.nextInt() , r= sc.nextInt() ;
            int result = equals[r-2]-equals[l-1]  ;
            if(s.charAt(l-1)==s.charAt(l))
                result++;
            out.println(result) ; }
        out.println();
        out.flush();
        out.close();
    }



    static class Graph
    {
        public int V;
        public LinkedList<Integer> adj[];
        Graph(int v)
        {
            V = v;
            visited = new boolean[v+1];
            distances = new Integer[v+1];
            for(int i = 0 ; i <v+1 ; i++)
                distances[i] = -1  ;
            adj = new LinkedList[v+1];
            for (int i=0; i<v+1; ++i)
                adj[i] = new LinkedList<Integer>();
        }
        void addEdge(int v, int w)
        {
            adj[v].add(w);
        }
        void dfs(int node) {
            visited[node]= true;
            System.out.print(node+" ");
            for(int x :adj[node]) {
                if(!visited[x])
                    dfs(x);
            }

        }
        void bfs(int node){
            Queue<Integer> q = new LinkedList<Integer>();   ;
            distances[node]= 0 ;
            q.add(node);
            while(!q.isEmpty()){
                int src = q.peek();
                System.out.print(src+" ");
                q.remove();
                int cost = distances[src];
                for(int child : adj[src]){
                    if(distances[child]==-1){
                        q.add(child);
                        distances[child]= cost+1;
                    }
                }
            }
        }
        public  int graph_height(int node) {
            int h = 0 ;
            for(int x : adj[node])
                h= Math.max(h,1+graph_height(x));

            return h ;

        }
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {

            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}
class Pair {
    int x ;
    int y ;
    public Pair(int x ,int y){
        this.x = x;
        this.y=y;}
}

class Pair1 implements Comparable{
    int x ;
    int y ;
    public Pair1(int x ,int y){
        this.x = x;
        this.y=y;}
    public int compareTo(Object o) {
        Pair1 a = (Pair1) o ;

        return (this.x-a.x);
    }

}
class Pair2 implements Comparable{
    int x ;
    int y ;
    public Pair2(int x ,int y){
        this.x = x;
        this.y=y;}
    public int compareTo(Object o) {
        Pair2 a = (Pair2) o ;

        return (this.y-a.y);
    }
}