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.*;
import static java.lang.Math.*;
import java.util.*;
import java.util.function.*;
import java.lang.*;

public class Main {
    final static boolean debug = false;
    final static String fileName = "";
    final static boolean useFiles = false;

    public static void main(String[] args) throws FileNotFoundException {
        long start;
        if (debug)
            start = System.nanoTime();
        InputStream inputStream;
        OutputStream outputStream;
        if (useFiles) {
            inputStream = new FileInputStream(fileName + ".in");
            outputStream = new FileOutputStream(fileName + ".out");
        } else {
            inputStream = System.in;
            outputStream = System.out;
        }
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task(in, out);
        solver.solve();
        if(debug)
            out.println((System.nanoTime() - start) / 1e+9);
        out.close();
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public double nextDouble(){
        return Double.parseDouble(next());
    }

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

    public long nextLong(){
        return Long.parseLong(next());
    }

    public byte nextByte(){
        return Byte.parseByte(next());
    }
}

class Task {
    public void solve() {
        String s = in.next();
        int n = s.length();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = (s.charAt(i) == ')' ? -1 : 1) + (i == 0 ? 0 : a[i - 1]);
        }
        BinaryOperatorSegmentTree tree = new BinaryOperatorSegmentTree(a, Math::min);

        int m = in.nextInt();
        for (int i = 0; i < m; i++) {
            int l = in.nextInt() - 1;
            int r = in.nextInt() - 1;

            int begin = l == 0 ? 0 : a[l - 1];
            int minx = tree.get(l, r) - begin;
            int end = a[r] - begin;
            int del = max(0, -minx) + (end - min(0, minx));
            out.println(r - l + 1 - del);
        }
    }

    private InputReader in;
    private PrintWriter out;

    Task(InputReader in, PrintWriter out) {
        this.in = in;
        this.out = out;
    }
}

class BinaryOperatorSegmentTree {
    private int[] t;
    private int n;
    private BinaryOperator<Integer> operator;

    BinaryOperatorSegmentTree(int n, BinaryOperator<Integer> operator) {
        this.n = n;
        t = new int[Integer.highestOneBit(n) << 2];
        this.operator = operator;
    }

    BinaryOperatorSegmentTree(int[] array, BinaryOperator<Integer> operator) {
        this(array.length, operator);
        build(0, 0, n - 1, array);
    }

    private void build(int v, int tl, int tr, int[] array) {
        if (tr == tl) {
            t[v] = array[tl];
        } else {
            int tm = (tl + tr) >> 1;
            build(2 * v + 1, tl, tm, array);
            build(2 * v + 2, tm + 1, tr, array);
            t[v] = operator.apply(t[2 * v + 1], t[2 * v + 2]);
        }
    }

    int get(int l, int r) {
        if (!(0 <= l && l < n && 0 <= r && r < n))
            throw new IllegalArgumentException("indices: (" + l + ", " + r + "). Bounds: (0, " + (n - 1) + ")");
        return get(0, 0, n - 1, l, r);
    }

    void set(int index, int value) {
        if (!(0 <= index && index < n))
            throw new IllegalArgumentException("index: " + index + ". Bounds: (0, " + (n - 1) + ")");
        set(0, 0, n - 1, index, value);
    }

    private int get(int v, int tl, int tr, int l, int r) {
        if (l > r)
            return Integer.MAX_VALUE;
        if (tl == l && tr == r)
            return t[v];
        int tm = (tl + tr) >> 1;
        return operator.apply(get(2 * v + 1, tl, tm, l, Math.min(tm, r)),
                get(2 * v + 2, tm + 1, tr, Math.max(tm + 1, l), r));
    }

    private void set(int v, int tl, int tr, int index, int value) {
        if (tr == tl)
            t[v] = value;
        else {
            int tm = (tl + tr) >> 1;
            if (index <= tm)
                set(2 * v + 1, tl, tm, index, value);
            else
                set(2 * v + 2, tm + 1, tr, index, value);
            t[v] = operator.apply(t[2 * v + 1], t[2 * v + 2]);
        }
    }

    public int[] toArray() {
        int[] result = new int[n];
        for (int i = 0; i < n; i++)
            result[i] = get(i, i);
        return result;
    }

    @Override
    public String toString() {
        String result = "";
        for (int i = 0; i < n; i++)
            result += get(i, i) + " ";
        return result;
    }
}