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.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Reader in = new Reader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {

    class ST {
        class Node {
            int match;
            int openUnused;
            int closeUnused;

            public String toString() {
                return "Node{" +
                        "match=" + match +
                        ", openUnused=" + openUnused +
                        ", closeUnused=" + closeUnused +
                        '}';
            }
        }

        Node nodes[];
        String input;

        private void refreshHelper(Node node, Node leftNode, Node rightNode) {
            node.match = leftNode.match + rightNode.match;

            int newMatch = Math.min(leftNode.openUnused, rightNode.closeUnused);
            node.match += newMatch;
            node.openUnused = leftNode.openUnused + rightNode.openUnused - newMatch;
            node.closeUnused = leftNode.closeUnused + rightNode.closeUnused - newMatch;
        }

        private void refreshNode(int nodeIdx) {
            Node node = nodes[nodeIdx];
            Node leftNode = nodes[nodeIdx*2+1];
            Node rightNode = nodes[nodeIdx*2+2];

            if (node == null) throw new RuntimeException("node is null at nodeIdx " + nodeIdx);
            if (leftNode == null) throw new RuntimeException("leftNode is null at nodeIdx " + nodeIdx);
            if (rightNode == null) throw new RuntimeException("rightNode is null at nodeIdx " + nodeIdx);
            refreshHelper(node, leftNode, rightNode);
        }

        private void buildTree(int nodeIdx, int left, int right) {
            Node node = nodes[nodeIdx];
            if (node == null) {
                node = new Node();
                nodes[nodeIdx] = node;
            }

            if (left == right) {
                node.match = 0;
                node.openUnused = (input.charAt(left) == '(') ? 1 : 0;
                node.closeUnused = (input.charAt(left) == ')') ? 1 : 0;
            }
            else {
                buildTree(nodeIdx * 2 + 1, left, (left + right) / 2);
                buildTree(nodeIdx*2 + 2, (left+right)/2 + 1, right);

                refreshNode(nodeIdx);
            }
        }

        public ST(String input) {
            this.input = input;
            nodes = new Node[4* input.length()];
            buildTree(0, 0, input.length()-1);
        }

        private Node query(int nodeIdx, int left, int right, final int queryLeft, final int queryRight) {
            try {
                //pwout.println("print " + nodeIdx + " " + left + " " + right);
                Node node = nodes[nodeIdx];
                if (queryLeft <= left && right <= queryRight) {
                    return node;
                }
                else if (right < queryLeft || left > queryRight) {
                    return new Node();
                }
                else {
                    Node leftRet = query(nodeIdx * 2 + 1, left, (left + right) / 2, queryLeft, queryRight);
                    Node rightRet = query(nodeIdx * 2 + 2, (left + right) / 2 + 1, right, queryLeft, queryRight);

                    Node ret = new Node();
                    refreshHelper(ret, leftRet, rightRet);

                    //pwout.println(ret.toString());
                    return ret;
                }
            }
            catch (Exception e) {
                throw new RuntimeException("Exception " + nodeIdx + " " + left + " " + right, e);
            }
        }

        public int getLongestBalancedSubsequence(int queryLeft, int queryRight) {
            return query(0, 0, input.length()-1, queryLeft, queryRight).match*2;
        }

    }

    PrintWriter pwout;
    public void solve(int testNumber, Reader in, PrintWriter out) {
        pwout = out;
        String s = in.next();
        ST st = new ST(s);

        int Q = in.nextInt();
        for (int q = 0; q < Q; q++) {
            int a, b;
            a = in.nextInt();
            b = in.nextInt();
            a--; b--;

            int ans = st.getLongestBalancedSubsequence(a, b);
            out.println(ans);
        }
    }
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    public Reader(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() {

        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            try {
                tokenizer = new StringTokenizer(
                        reader.readLine() );
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return tokenizer.nextToken();
    }

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

}

