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.StringTokenizer;

public class Task381E {

    public static void main(String[] args) throws IOException {
        InputScanner is = new InputScanner();
        String s = is.next();
        char[] brackets = s.toCharArray();
        SegmentTree st = new SegmentTree(brackets);
        int m = is.nextInt();
        for (int i = 0; i < m; i++) {
            int l = is.nextInt() - 1;
            int r = is.nextInt() - 1;
            System.out.println(2 * st.getSum(brackets.length, l, r));
        }
    }

    static class SegmentTree {
        int[] tree;
        int[] openBrackets;
        int[] closeBrackets;
        int leftBrackets = 0;
        int rightBrackets = 0;
        int additionalBrackets = 0;

        public SegmentTree(char[] elements) {
            int n = elements.length;
            int treeHeight = (int) (Math.ceil(Math.log(n) / Math.log(2)));
            int treeSize = 2 * (int) Math.pow(2, treeHeight) - 1;
            tree = new int[treeSize];
            openBrackets = new int[treeSize];
            closeBrackets = new int[treeSize];
            constructSegmentTree(elements, 0, elements.length - 1, 0);
        }

        private int getMid(int s, int e) {
            return s + (e - s) / 2;
        }

        private void constructSegmentTree(char[] elements, int segmentStart, int segmentEnd, int currentNode) {
            if (segmentStart == segmentEnd) {
                tree[currentNode] = 0;
                if (elements[segmentStart] == '(') openBrackets[currentNode] = 1;
                else closeBrackets[currentNode] = 1;
                return;
            }
            int mid = getMid(segmentStart, segmentEnd);
            constructSegmentTree(elements, segmentStart, mid, currentNode * 2 + 1);
            constructSegmentTree(elements, mid + 1, segmentEnd, currentNode * 2 + 2);

            int t = Math.min(openBrackets[currentNode * 2 + 1], closeBrackets[currentNode * 2 + 2]);
            tree[currentNode] = tree[currentNode * 2 + 1] + tree[currentNode * 2 + 2] + t;
            openBrackets[currentNode] = openBrackets[currentNode * 2 + 1] + openBrackets[currentNode * 2 + 2] - t;
            closeBrackets[currentNode] = closeBrackets[currentNode * 2 + 1] + closeBrackets[currentNode * 2 + 2] - t;
        }

        int getSumUtil(int segmentStart, int segmentEnd, int queryStart, int queryEnd, int currentNode) {
            if (segmentStart > segmentEnd || segmentStart > queryEnd || segmentEnd < queryStart)
                return 0;

            if (segmentStart >= queryStart && segmentEnd <= queryEnd) {
                if (closeBrackets[currentNode] < leftBrackets) {
                    additionalBrackets += closeBrackets[currentNode];
                    leftBrackets -= closeBrackets[currentNode];
                } else {
                    additionalBrackets += leftBrackets;
                    leftBrackets = 0;
                }
                leftBrackets += openBrackets[currentNode];
                return tree[currentNode];
            }

            int mid = getMid(segmentStart, segmentEnd);
            return getSumUtil(segmentStart, mid, queryStart, queryEnd, 2 * currentNode + 1) +
                    getSumUtil(mid + 1, segmentEnd, queryStart, queryEnd, 2 * currentNode + 2);
        }

        int getSum(int n, int qs, int qe) {
            leftBrackets = 0;
            rightBrackets = 0;
            additionalBrackets = 0;
            return getSumUtil(0, n - 1, qs, qe, 0) + additionalBrackets;
        }

    }

    static class InputScanner {
        BufferedReader br;
        StringTokenizer st;

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

        public String next() throws IOException {
            if (st == null || !st.hasMoreTokens()) {
                String line = br.readLine();
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            String next = next();
            return Integer.parseInt(next);
        }

        public long nextLong() throws IOException {
            String next = next();
            return Long.parseLong(next);
        }
    }
}
