Sereja has a bracket sequence s1, s2, ..., sn, or, in other words, a string s of length n, consisting of characters "(" and ")".

Sereja needs to answer m queries, each of them is described by two integers li, ri (1 ≤ li ≤ ri ≤ n). The answer to the i-th query is the length of the maximum correct bracket subsequence of sequence sli, sli + 1, ..., sri. Help Sereja answer all queries.

You can find the definitions for a subsequence and a correct bracket sequence in the notes.

Input

The first line contains a sequence of characters s1, s2, ..., sn (1 ≤ n ≤ 106) without any spaces. Each character is either a "(" or a ")". The second line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains a pair of integers. The i-th line contains integers li, ri (1 ≤ li ≤ ri ≤ n) — the description of the i-th query.

Output

Print the answer to each question on a single line. Print the answers in the order they go in the input.

Examples

Input

())(())(())(
7
1 1
2 3
1 2
1 12
8 12
5 11
2 10


Output

0
0
2
10
4
6
6

Note

A subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is string x = sk1sk2... sk|x| (1 ≤ k1 < k2 < ... < k|x| ≤ |s|).

A correct bracket sequence is a bracket sequence that can be transformed into a correct aryphmetic expression by inserting characters "1" and "+" between the characters of the string. For example, bracket sequences "()()", "(())" are correct (the resulting expressions "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.

For the third query required sequence will be «()».

For the fourth query required sequence will be «()(())(())».
import java.util.*;
import java.lang.*;
import java.io.*;
 
public class Main
{
	//Fast IO class
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
        public FastReader() 
        { 
        	boolean env=System.getProperty("ONLINE_JUDGE") != null;
        	if(!env) {
        		try {
					br=new BufferedReader(new FileReader("src\\input.txt"));
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				}
        	}
        	else {
        		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; 
        } 
    }     
    static long MOD=1000000000+7;
    //Euclidean Algorithm
    static long gcd(long A,long B){
        if(B==0) return A;
        return gcd(B,A%B);
    }
    //Modular Exponentiation
    static long fastExpo(long x,long n){
        if(n==0) return 1;
        if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;
        return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;
    }
    //Prime Number Algorithm
    static boolean isPrime(long n){
        if(n<=1) return false;
        if(n<=3) return true;
        if(n%2==0 || n%3==0) return false;
        for(int i=5;i*i<=n;i+=6)
            if(n%i==0 || n%(i+2)==0) return false;
        return true;
    }
    //Sieve of eratosthenes
    static int[] findPrimes(int n){
        boolean isPrime[]=new boolean[n+1];
        ArrayList<Integer> a=new ArrayList<>();
        int result[];
        Arrays.fill(isPrime,true);
        isPrime[0]=false;
        isPrime[1]=false;
        for(int i=2;i*i<=n;++i)
            if(isPrime[i]==true)
                for(int j=i*i;j<=n;j+=i) isPrime[j]=false;
        for(int i=0;i<=n;i++) if(isPrime[i]==true) a.add(i);
        result=new int[a.size()];
        for(int i=0;i<a.size();i++) result[i]=a.get(i);
        return result;
    } 
    // Pair
    static class pair{
    	long x,y;
    	pair(long a,long b){
    		this.x=a;
    		this.y=b;
    	}
    	public boolean equals(Object obj) {
    		if(obj == null || obj.getClass()!= this.getClass()) 
                return false;
            pair p = (pair) obj;
            return (this.x==p.x && this.y==p.y);
        }
    	public int hashCode() {
            return Objects.hash(x, y);
        }
    }
    //Main function(The main code starts from here)
    static class node{
    	int x,y,z;
    	node(int a,int b,int c){
    		x=a;
    		y=b;
    		z=c;
    	}
    }
    static char s[];
    static node seg[];
    static void init(int n) {
    	seg=new node[4*n];
    }
    static void union(int root) {
    	seg[root]=new node(0,0,0);
    	int tmp=Math.min(seg[2*root+1].y, seg[2*root+2].z);
    	seg[root].x=seg[2*root+1].x+seg[2*root+2].x+tmp;
    	seg[root].y=seg[2*root+1].y+seg[2*root+2].y-tmp;
    	seg[root].z=seg[2*root+1].z+seg[2*root+2].z-tmp;
    }
    static void build(int root,int l,int r) {
    	if(l==r) {
    		if(s[l]=='(') seg[root]=new node(0,1,0);
    		else seg[root]=new node(0,0,1);
    		return;
    	}
    	int mid=l+(r-l)/2;
    	build(2*root+1,l,mid);
    	build(2*root+2,mid+1,r);
    	union(root);
    }
    static node query(int root,int l,int r,int x,int y) {
    	if(y<l || r<x) return new node(0,0,0);
    	if(x<=l && r<=y) return seg[root];
    	int mid=l+(r-l)/2;
    	node a=query(2*root+1,l,mid,x,y);
    	node b=query(2*root+2,mid+1,r,x,y);
    	node c=new node(0,0,0);
    	int tmp=Math.min(a.y, b.z);
    	c.x=a.x+b.x+tmp;
    	c.y=a.y+b.y-tmp;
    	c.z=a.z+b.z-tmp;
    	return c;
    }
    public static void main (String[] args) throws java.lang.Exception
    {
        FastReader sc=new FastReader();
    	int test=1;
        while(test-->0) {
        	s=sc.nextLine().toCharArray();
        	int n=s.length;
        	init(n);
        	build(0,0,n-1);
        	StringBuilder sb=new StringBuilder();
        	int q=sc.nextInt();
        	while(q-->0) {
        		sb.append(2*query(0,0,n-1,sc.nextInt()-1,sc.nextInt()-1).x+"\n");
        	}
        	System.out.println(sb);
        }
    }
}