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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class CF{public static void main(String[] args){S s=new S();s.s();s.output();}}class S{
    Node[] tree;
    void s() {
        String str = NS();
        int n = str.length();
        tree = new Node[4 * n];
        buildTree(str, 1, 0, n - 1);
        int m = NI();
        for (int i = 0; i < m; i++)
            sout(get(1, 1, n, NI(), NI()).a << 1);
    }

    void buildTree(String s, int v, int l, int r) {
        if (l == r) {
            tree[v] = Node.parseBracket(s.charAt(l));
            return;
        }
        int mid = (l + r) >> 1;
        buildTree(s, 2 * v, l, mid);
        buildTree(s, 2 * v + 1, mid + 1, r);
        int tS = min(tree[2 * v].o, tree[2 * v + 1].c);
        tree[v] = new Node(tree[2 * v].o + tree[2 * v + 1].o - tS, tree[2 * v].a + tree[2 * v + 1].a + tS, tree[2 * v].c + tree[2 * v + 1].c - tS);
    }

    Node get(int v, int tl, int tr, int l, int r) {
        if (r < l) return Node.nullNode;
        if (l == tl && r == tr) return tree[v];
        int mid = (tl + tr) >> 1;
        Node t1 = get(2 * v, tl, mid, l, min(r, mid));
        Node t2 = get(2 * v + 1, mid + 1, tr, max(l, mid + 1), r);
        int tS = min(t1.o, t2.c);
        return new Node(t1.o + t2.o - tS, t1.a + t2.a + tS, t1.c + t2.c - tS);
    }

    BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));StringTokenizer st=new StringTokenizer("");final long LINF=Long.MAX_VALUE;
    StringBuilder output=new StringBuilder();final int INF=Integer.MAX_VALUE;void sout(Object x){output.append(x.toString()).append('\n');}
    void inLong(long[]a,int n){for(int i=0;i<n;i++)a[i]=NL();}int min(int i1,int i2){return i1<i2?i1:i2;}double ND(){return Double.parseDouble(NS());}
    long min(long i1,long i2){return i1<i2?i1:i2;}int max(int i1,int i2){return i1>i2?i1:i2;}long max(long i1,long i2){return i1>i2?i1:i2;}
    String NS(){while(!st.hasMoreTokens())try{st=new StringTokenizer(stdin.readLine());}catch(IOException ignored){}return st.nextToken();}
    int NI(){return Integer.parseInt(NS());}long NL(){return Long.parseLong(NS());}String NLn()throws IOException{return stdin.readLine();}
    int abs(int x){return x<0?-x:x;}long abs(long x){return x<0?-x:x;}void sout(){output.append('\n');}void out(Object x){output.append(x.toString());}
    int mod(int x,int mod){return(x+mod)%mod;}void output(){System.out.print(output);}void inInt(int[]a,int n){for(int i=0;i<n;i++)a[i]=NI();}
}

class Node {
    int o, a, c;
    static Node nullNode = new Node(0, 0, 0);
    Node(int o, int a, int c) {
        this.o = o;
        this.a = a;
        this.c = c;
    }
    static Node parseBracket(char br) {
        int f = br == '(' ? 1 : 0;
        return new Node(f, 0, 1 - f);
    }
}