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.io.*;
import java.util.*;
public class Serejandbrackets {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.flush();out.close();
    }
        static class TaskE {
         class pair{
          int cnt,l,r;pair(int a,int b,int c){cnt=a;l=b;r=c;}
         }
         String S;pair seg[];
         void b(int n,int s,int e){
          if(s==e){
           if(S.charAt(s)=='('){
            seg[n].l++;
           }else seg[n].r++;
           return;
          }
          int m=(s+e)>>1;
          b(2*n+1,s,m);b(2*n+2,m+1,e);
          int x=Math.min(seg[2*n+1].l,seg[2*n+2].r);
          seg[n].cnt+=seg[2*n+1].cnt+seg[2*n+2].cnt+2*x;
          seg[n].l=seg[2*n+1].l+seg[2*n+2].l-x;
          seg[n].r=seg[2*n+1].r+seg[2*n+2].r-x;
         }
         pair q(int n,int s,int e,int qs,int qe){
          if(s>qe||e<qs)return new pair(0,0,0);
          if(s>=qs&&e<=qe){
           return seg[n];
          }int m=(s+e)>>1;
          pair L=q(2*n+1,s,m,qs,qe);
          pair R=q(2*n+2,m+1,e,qs,qe);
          int cnt=L.cnt+R.cnt;
          int x=Math.min(L.l,R.r);
          return new pair(cnt+2*x,L.l+R.l-x,L.r+R.r-x);
         }
         public void solve(int testNumber, InputReader in, PrintWriter out) {
            S=in.next().trim();
            int l=S.length();seg=new pair[4*l];
            for(int i=0;i<4*l;i++)seg[i]=new pair(0,0,0);
            b(0,0,l-1);
            int q=in.nextInt();
            while(q-->0){
             int L=in.nextInt()-1,R=in.nextInt()-1;
             out.println(q(0,0,l-1,L,R).cnt);
            }
         }
    }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;
        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

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

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}