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 java.util.*;

public class C {
	public static void main(String[] args) {
		new C().run();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

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

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

	int[] tree;

	public int min(int v, int l, int r, int a, int b) {
		if (r < a || b < l)
			return Integer.MAX_VALUE;
		if (a <= l && r <= b)
			return tree[v];

		return Math.min(min(2 * v, l, (l + r) / 2, a, b),
				min(2 * v + 1, (l + r) / 2 + 1, r, a, b));
	}

	public void solve() throws IOException {
		char[] c = nextToken().toCharArray();

		int[] open = new int[c.length + 1];
		int[] balance = new int[c.length + 1];
		for (int i = 1; i < c.length + 1; i++) {
			open[i] = open[i - 1] + (c[i - 1] == '(' ? 1 : 0);
			balance[i] = balance[i - 1] + (c[i - 1] == '(' ? 1 : -1);
		}

		int k = 1;
		while (c.length >= k) {
			k *= 2;
		}
		tree = new int[2 * k + 1];
		Arrays.fill(tree, Integer.MAX_VALUE);
		for (int i = 0; i < c.length; i++) {
			tree[i + k] = balance[i + 1];
		}

		for (int i = k - 1; i > 0; i--) {
			tree[i] = Math.min(tree[2 * i], tree[2 * i + 1]);
		}

		int m = nextInt();
		for (int i = 0; i < m; i++) {
			int l = nextInt();
			int r = nextInt();

			int o = open[r] - open[l - 1];
			int closed = r - l + 1 - o;

			int min = min(1, 1, k, l, r) - balance[l - 1];

			min = Math.min(0, min);

			out.println(2 * Math.min(o, closed + min));
		}
	}

	public void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
