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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author pandusonu
 */
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);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public Node[] segTree;

        public TaskC() {
            segTree = new Node[2 * (int) Math.pow(10, 7) + 100];
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            // out.print("Case #" + testNumber + ": ");
            String s = in.readString();
            int n = s.length();
            make(1, 0, n - 1, s);
            int m = in.readInt();
            for (int i = 0; i < m; i++) {
                int u = in.readInt() - 1;
                int v = in.readInt() - 1;
                out.println(2 * query(1, 0, n - 1, u, v).a);
            }
        }

        public Node query(int node, int start, int end, int l, int r) {
            if (r < start || end < l)
                return null;
            if (l <= start && end <= r)
                return segTree[node];
            int mid = (start + end) >> 1;
            Node n1 = query(node << 1, start, mid, l, r);
            Node n2 = query(node << 1 | 1, mid + 1, end, l, r);
            if (n1 != null && n2 != null) {
                int temp = Math.min(n1.b, n2.c);
                return new Node(n1.a + n2.a + temp,
                        n1.b + n2.b - temp,
                        n1.c + n2.c - temp);
            }
            if (n1 == null)
                return n2;
            return n1;
        }

        public void make(int node, int start, int end, String s) {
            if (start > end) return;
            if (start == end) {
                if (s.charAt(start) == '(')
                    segTree[node] = new Node(0, 1, 0);
                else segTree[node] = new Node(0, 0, 1);
                return;
            }
            int mid = (start + end) >> 1;
            make(node << 1, start, mid, s);
            make(node << 1 | 1, mid + 1, end, s);
            int temp = Math.min(segTree[node << 1].b, segTree[node << 1 | 1].c);
            segTree[node] = new Node(segTree[node << 1].a + segTree[node << 1 | 1].a + temp,
                    segTree[node << 1].b + segTree[node << 1 | 1].b - temp,
                    segTree[node << 1].c + segTree[node << 1 | 1].c - temp);
        }

    }

    static class Node {
        int a;
        int b;
        int c;

        Node(int aa, int bb, int cc) {
            a = aa;
            b = bb;
            c = cc;
        }

    }

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

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

        private int read() {
            try {
                if (curChar >= numChars) {
                    curChar = 0;
                    numChars = stream.read(buf);
                    if (numChars <= 0)
                        return -1;
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return buf[curChar++];
        }

        public int readInt() {
            return (int) readLong();
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
                if (c == -1) throw new RuntimeException();
            }
            boolean negative = false;
            if (c == '-') {
                negative = true;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += (c - '0');
                c = read();
            } while (!isSpaceChar(c));
            return negative ? (-res) : (res);
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}

