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.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class CSerejaAndBrackets {
        static CSerejaAndBrackets.triple[] st;
        static String s;

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

        CSerejaAndBrackets.triple MaxUtil(int ss, int se, int l,
                                          int r, int node) {
            if (l <= ss && r >= se)
                return st[node];

            if (se < l || ss > r)
                return new CSerejaAndBrackets.triple(0, 0, 0);

            int mid = getMid(ss, se);
            CSerejaAndBrackets.triple a = MaxUtil(ss, mid, l, r, 2 * node + 1);
            CSerejaAndBrackets.triple b = MaxUtil(mid + 1, se, l, r, 2 * node + 2);
            int correct = Math.min(a.y, b.z);
            return new CSerejaAndBrackets.triple(a.x + b.x + 2 * correct, a.y + b.y - correct, a.z + b.z - correct);
        }

        int getMax(int n, int l, int r) {
            return MaxUtil(0, n - 1, l, r, 0).x;
        }

        CSerejaAndBrackets.triple constructSTUtil(int ss, int se, int si) {
            if (ss == se) {
                if (s.charAt(ss) == '(') {
                    st[si] = new CSerejaAndBrackets.triple(0, 1, 0);
                } else {
                    st[si] = new CSerejaAndBrackets.triple(0, 0, 1);
                }
                return st[si];
            }

            int mid = getMid(ss, se);

            CSerejaAndBrackets.triple a = constructSTUtil(ss, mid, si * 2 + 1);
            CSerejaAndBrackets.triple b = constructSTUtil(mid + 1, se, si * 2 + 2);
            int correct = Math.min(a.y, b.z);
            st[si] = new CSerejaAndBrackets.triple(a.x + b.x + 2 * correct, a.y + b.y - correct, a.z + b.z - correct);
            return st[si];
        }

        void constructST(int n) {
            int x = (int) (Math.ceil(Math.log(n) / Math.log(2)));
            int max_size = 2 * (1 << x) - 1;
            st = new CSerejaAndBrackets.triple[max_size];
            constructSTUtil(0, n - 1, 0);
        }

        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            s = sc.nextLine();
            constructST(s.length());
            int n = sc.nextInt();
            for (int i = 0; i < n; i++) {
                out.println(getMax(s.length(), sc.nextInt() - 1, sc.nextInt() - 1));
            }
        }

        static class triple {
            int x;
            int y;
            int z;

            public triple(int x, int y, int z) {
                this.x = x;
                this.y = y;
                this.z = z;
            }

        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}

