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

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

    static class SerjaAndBrackets {
        int[] tree;
        int[] balance;

        void build(int root, int left, int right) {
            if (left == right) {
                tree[root] = balance[left];
                return;
            }
            int mid = (left + right) >>> 1;
            build(root * 2 + 1, left, mid);
            build(root * 2 + 2, mid + 1, right);
            tree[root] = Math.min(tree[root * 2 + 1], tree[root * 2 + 2]);
        }

        int query(int root, int lc, int rc, int left, int right) {
            if (left > right) return Integer.MAX_VALUE / 2;
            if (left == lc && right == rc) return tree[root];
            int mid = (lc + rc) >>> 1;
            return Math.min(query(root * 2 + 1, lc, mid, left, Math.min(right, mid)),
                    query(root * 2 + 2, mid + 1, rc, Math.max(mid + 1, left), right));
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            balance = new int[s.length() + 1];
            for (int i = 0; i < s.length(); i++) {
                balance[i + 1] = balance[i] + (s.charAt(i) == '(' ? 1 : -1);
            }
            tree = new int[4 * s.length() + 20];
            build(0, 0, balance.length - 1);
            int n = in.nextInt();
            while (n-- > 0) {
                int left = in.nextInt() - 1;
                int right = in.nextInt();
                long minValue = query(0, 0, balance.length - 1, left, right);
                long leftB = balance[left];
                long rightB = balance[right];
                long opened = leftB - minValue;
                long closed = rightB - leftB + opened;
                out.println(right - left - opened - closed);
            }
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (this.numChars == -1) {
                throw new InputMismatchException();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;

                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException ex) {
                        throw new InputMismatchException();
                    }

                    if (this.numChars <= 0) {
                        return -1;
                    }
                }

                return this.buf[this.curChar++];
            }
        }

        public int nextInt() {
            int c;
            for (c = this.read(); isSpaceChar(c); c = this.read()) {
            }

            byte sgn = 1;
            if (c == 45) {
                sgn = -1;
                c = this.read();
            }

            int res = 0;

            while (c >= 48 && c <= 57) {
                res *= 10;
                res += c - 48;
                c = this.read();
                if (isSpaceChar(c)) {
                    return res * sgn;
                }
            }

            throw new InputMismatchException();
        }

        public String next() {
            int c;
            while (isSpaceChar(c = this.read())) {
            }

            StringBuilder result = new StringBuilder();
            result.appendCodePoint(c);

            while (!isSpaceChar(c = this.read())) {
                result.appendCodePoint(c);
            }

            return result.toString();
        }

        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
        }

    }
}

