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.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Alex
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }
    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            char[] a = in.next().toCharArray();
            int[] partial = new int[a.length + 1];
            for (int i = 1; i <= a.length; i++) partial[i] = partial[i - 1] + (a[i - 1] == '(' ? 1 : -1);
            int[] pospartial = new int[a.length + 1];
            for (int i = 1; i <= a.length; i++) pospartial[i] = pospartial[i - 1] + (a[i - 1] == '(' ? 1 : 0);
            MS ms = new MS(partial);
            int queries = in.readInt();
            for (int query = 0; query < queries; query++) {
                int l = in.readInt() - 1, r = in.readInt() - 1;
                int pos = pospartial[r + 1] - pospartial[l];
                int neg = r - l + 1 - pos;
                int unusable = Math.min(0, (int) ms.query(l + 1, r + 1) - partial[l]);
                out.printLine(Math.min(pos, neg + unusable) * 2);
            }
        }
        class MS {
            int BAD = 100000000;
            int[] a;
            int[] leftarr;
            int[] rightarr;
            int[] minvalarr;
            void init(int index, int left, int right) {
                if (left > right) return;
                leftarr[index] = left;
                rightarr[index] = right;
                minvalarr[index] = a[left];
                if (left == right) return;
                int middle = (left + right) / 2;
                init(2 * index + 1, left, middle);
                init(2 * index + 2, middle + 1, right);
                minvalarr[index] = Math.min(minvalarr[2 * index + 1], minvalarr[2 * index + 2]);
            }
            int queryhelper(int index, int left, int right) {
                if (leftarr[index] == BAD) return BAD;
                if (leftarr[index] > right || rightarr[index] < left) return BAD;
                if (leftarr[index] >= left && rightarr[index] <= right) return minvalarr[index];
                return Math.min(queryhelper(2 * index + 1, left, right), queryhelper(2 * index + 2, left, right));
            }
            int query(int left, int right) {
                return queryhelper(0, left, right);
            }
            public MS(int[] a) {
                this.a = a;
                leftarr = new int[a.length * 4 + 10];
                Arrays.fill(leftarr, BAD);
                rightarr = new int[a.length * 4 + 10];
                minvalarr = new int[a.length * 4 + 10];
                Arrays.fill(minvalarr, BAD);
                init(0, 0, a.length - 1);
            }
        }
    }
    static class OutputWriter {
        private final PrintWriter writer;
        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }
        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }
        public void close() {
            writer.close();
        }
        public void printLine(int i) {
            writer.println(i);
        }
    }
    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 readInt() {
            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);
        }
    }
}

