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.InputMismatchException;
import java.util.Stack;

public class C380 {
    public static void main(String[] args) {
        InputReader scanner = new InputReader(new BufferedInputStream(System.in));
        PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));

        char[] str = scanner.next().toCharArray();

        Stack<Integer> st = new Stack<Integer>();
        Node[] tree = new Node[str.length * 4];
        for (int i = 0; i < tree.length; i++) {
            tree[i] = new Node();
        }

        for (int i = 0; i < str.length; i++) {
            if (str[i] == '(') {
                st.push(i);
                continue;
            }

            if (st.empty()) continue;

            int lx = st.pop();

            insert(tree, 0, 0, str.length - 1, lx, 1);
            insert(tree, 0, 0, str.length - 1, i, -1);
        }

        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            int a = scanner.nextInt() - 1;
            int b = scanner.nextInt() - 1;

            int res = query(tree, 0, 0, str.length - 1, a, b)[1];

            writer.println(res * 2);
        }
        writer.flush();
        writer.close();
    }

    static class Node {
        int l;
        int r;
        int c;
    }


    static void insert(Node[] tree, int root, int l, int r, int ix, int value) {
        if (!(l <= ix && ix <= r)) return;

        if (l == r) {

            if (value == -1)
                tree[root].r = 1;
            else
                tree[root].l = 1;

            return;
        }

        int mid = (l + r) / 2;
        int lx = root * 2 + 1;
        int rx = root * 2 + 2;

        insert(tree, lx, l, mid, ix, value);
        insert(tree, rx, mid + 1, r, ix, value);

        tree[root].r = tree[lx].r + tree[rx].r;
        tree[root].l = tree[lx].l + tree[rx].l;
        tree[root].c = tree[lx].c + tree[rx].c;
        int c = Math.min(tree[lx].l, tree[rx].r);
        tree[root].r -= c;
        tree[root].l -= c;
        tree[root].c += c;
    }

    static final int[] zero = new int[]{0, 0, 0};

    static int[] query(Node[] tree, int root, int l, int r, int sl, int sr) {
        if (sr < l || r < sl) return zero;
        if (sl <= l && r <= sr) {
            return new int[]{tree[root].l, tree[root].c, tree[root].r};
        }

        int mid = (l + r) / 2;

        int[] left = query(tree, root * 2 + 1, l, mid, sl, sr);
        int[] right = query(tree, root * 2 + 2, mid + 1, r, sl, sr);

        int[] res = new int[]{left[0] + right[0], left[1] + right[1], left[2] + right[2]};

        int c = Math.min(left[0], right[2]);

        res[0] -= c;
        res[1] += c;
        res[2] -= c;

        return res;
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;
        public InputReader(InputStream stream) {
            this.stream = stream;
        }
        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }
        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c))
                    res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }
        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
        public String next() {
            return readString();
        }
        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}
