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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;


public class CF223D1C {
    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;

    public void solve() throws IOException {
        String S = reader.readLine();
        SegmentTree tree = new SegmentTree(S);
        int Q = nextInt();
        for (int q = 0; q < Q; q++) {
            out.println(tree.query(nextInt()-1, nextInt()-1) * 2);
        }
    }

    public class SegmentTree{
        String S;
        int length;
        int[] pairs;
        int[] open;
        int[] close;

        public SegmentTree(String S) {
            int size = Integer.highestOneBit(S.length()) * 4;
            this.S = S;
            this.length = S.length();
            this.pairs = new int[size];
            this.open = new int[size];
            this.close = new int[size];
            init(0, 0, length-1);
        }

        private void init(int node, int b, int e) {
            if (b == e) {
                if (S.charAt(b) == ')') close[node] = 1;
                if (S.charAt(b) == '(') open[node] = 1;
            } else {
                int mid = (b + e) / 2;
                int n1 = node * 2 + 1;
                int n2 = node * 2 + 2;
                init(n1, b, mid);
                init(n2, mid + 1, e);
                int tmp = Math.min(open[n1], close[n2]);
                pairs[node] = pairs[n1] + pairs[n2] + tmp;
                open[node] = open[n1] + open[n2] - tmp;
                close[node] = close[n1] + close[n2] - tmp;
            }
        }

        public int query(int l, int r){
            int[] ans = queryInternal(0, 0, length-1, l, r);
            return ans[0];
        }

        private int[] queryInternal(int node, int b, int e, int l, int r){
            if( l > e || r < b ) return new int[] {0, 0, 0};
            if( b >= l && e <= r ) return new int[] {pairs[node], open[node], close[node]};
            int mid = (b + e) / 2;
            int[] r1 = queryInternal(node * 2 + 1, b, mid, l , r);
            int[] r2 = queryInternal(node * 2 + 2, mid+1, e, l, r);
            int tmp = Math.min(r1[1], r2[2]);
            return new int[] {r1[0] + r2[0] + tmp, r1[1] + r2[1] - tmp, r1[2] + r2[2] - tmp};
        }
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        new CF223D1C().run();
    }

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            out = new PrintWriter(System.out);
            solve();
            reader.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}
