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.Scanner;

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

    static class TaskC {
        int n;
        int[] t;
        int[] left;
        int[] right;
        String s;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            s = in.nextLine();

            n = s.length();
            t = new int[n * 4 + 1];
            left = new int[n * 4 + 1];
            right = new int[n * 4 + 1];

            build(0, n, 1);

            int m = in.nextInt();
            for (int i = 0; i < m; i++) {
                int l = in.nextInt();
                int r = in.nextInt();
                out.println(query(l - 1, r, 0, n, 1)[0]);
            }
        }

        void build(int l, int r, int id) {
            if (r - l < 2) {
                t[id] = 0;
                if (s.charAt(l) == '(') left[id] = 1;
                else right[id] = 1;
                return;
            }

            int mid = (l + r) / 2;
            build(l, mid, id * 2);
            build(mid, r, id * 2 + 1);

            int new_correct = Math.min(left[id * 2], right[id * 2 + 1]);
            t[id] = t[id * 2] + t[id * 2 + 1] + 2 * new_correct;
            left[id] = left[id * 2] + left[id * 2 + 1] - new_correct;
            right[id] = right[id * 2] + right[id * 2 + 1] - new_correct;
        }

        int[] query(int x, int y, int l, int r, int id) {
            if (r <= x || l >= y) {
                int[] res = {0, 0, 0};
                return res;
            }

            if (x <= l && r <= y) {
                int[] res = {t[id], left[id], right[id]};
                return res;
            }

            int mid = (l + r) / 2;
            int[] a = query(x, y, l, mid, id * 2);
            int[] b = query(x, y, mid, r, id * 2 + 1);

            int new_correct = Math.min(a[1], b[2]);
            int t = a[0] + b[0] + 2 * new_correct;
            int new_left = a[1] + b[1] - new_correct;
            int new_right = a[2] + b[2] - new_correct;
            int[] res = {t, new_left, new_right};
            return res;
        }

    }
}

