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

/**
 * 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;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {

	public void solve(int testNumber, InputReader in, PrintWriter out) {
		String s = in.next();
		int n = s.length();
		int[] balance = new int[n + 1];
		balance[0] = 0;
		for (int i = 0; i < n; ++i) {
			balance[i + 1] = balance[i] + (s.charAt(i) == '(' ? 1 : -1);
		}
		SegmentTree t = new SegmentTree(n + 1);
		for (int i = 0; i < n + 1; i++) {
			t.modify(i, i, balance[i]);
		}
		int m = in.nextInt();
		for (int qi = 0; qi < m; ++qi) {
			int l = in.nextInt() - 1;
			int r = in.nextInt();
			int minBalance = t.query(l, r);
			int leftBalance = balance[l];
			int rightBalance = balance[r];
			int skipOpens = leftBalance - minBalance;
			int skipCloses = rightBalance - leftBalance + skipOpens;
			out.println(r - l - skipOpens - skipCloses);
		}
	}

	public class SegmentTree {

		// Modify the following 5 methods to implement your custom operations on the tree.
		// This example implements Add/Max operations. Operations like Add/Sum, Set/Max can also be implemented.
		int modifyOperation(int x, int y) {
			// treat neutral delta separately
			if (x == getNeutralDelta()) {
				return y;
			}
			if (y == getNeutralDelta()) {
				return x;
			}
			// define operation here
			return x + y;
		}

		int queryOperation(int x, int y) {
			return Math.min(x, y);
		}

		int deltaEffectOnSegment(int delta, int segmentLength) {
			// Here you must write a fast equivalent of following slow code:
			// int result = delta;
			// for (int i = 0; i < segmentLength - 1; i++) result = queryOperation(result, delta);
			// return result;
			return delta;
		}

		int getNeutralDelta() {
			return Integer.MIN_VALUE;
		}

		int getInitValue() {
			return 0;
		}

		// generic code
		int[] value;
		int[] delta; // delta[i] affects value[i], delta[2*i+1] and delta[2*i+2]
		int[] len;

		void pushDelta(int i) {
			int d = 0;
			for (; (i >> d) > 0; d++) {
			}
			for (d -= 2; d >= 0; d--) {
				int x = i >> d;
				value[x >> 1] = joinValueWithDelta(x >> 1);
				delta[x] = modifyOperation(delta[x], delta[x >> 1]);
				delta[x ^ 1] = modifyOperation(delta[x ^ 1], delta[x >> 1]);
				delta[x >> 1] = getNeutralDelta();
			}
		}

		public SegmentTree(int n) {
			value = new int[2 * n];
			for (int i = 0; i < n; i++) {
				value[i + n] = getInitValue();
			}
			for (int i = 2 * n - 1; i > 1; i -= 2) {
				value[i >> 1] = queryOperation(value[i], value[i ^ 1]);
			}

			delta = new int[2 * n];
			Arrays.fill(delta, getNeutralDelta());

			len = new int[2 * n];
			Arrays.fill(len, n, 2 * n, 1);
			for (int i = 2 * n - 1; i > 1; i -= 2) {
				len[i >> 1] = len[i] + len[i ^ 1];
			}
		}

		int joinValueWithDelta(int i) {
			return modifyOperation(value[i], deltaEffectOnSegment(delta[i], len[i]));
		}

		public int query(int a, int b) {
			a += value.length >> 1;
			b += value.length >> 1;
			pushDelta(a);
			pushDelta(b);
			int res = 0;
			boolean found = false;
			for (; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {
				if ((a & 1) != 0) {
					res = found ? queryOperation(res, joinValueWithDelta(a)) : joinValueWithDelta(a);
					found = true;
				}
				if ((b & 1) == 0) {
					res = found ? queryOperation(res, joinValueWithDelta(b)) : joinValueWithDelta(b);
					found = true;
				}
			}
			if (!found)
				throw new RuntimeException();
			return res;
		}

		public void modify(int a, int b, int delta) {
			a += value.length >> 1;
			b += value.length >> 1;
			pushDelta(a);
			pushDelta(b);
			int ta = -1;
			int tb = -1;
			for (; a <= b; a = (a + 1) >> 1, b = (b - 1) >> 1) {
				if ((a & 1) != 0) {
					this.delta[a] = modifyOperation(this.delta[a], delta);
					if (ta == -1) {
						ta = a;
					}
				}
				if ((b & 1) == 0) {
					this.delta[b] = modifyOperation(this.delta[b], delta);
					if (tb == -1) {
						tb = b;
					}
				}
			}
			for (int i = ta; i > 1; i >>= 1) {
				value[i >> 1] = queryOperation(joinValueWithDelta(i), joinValueWithDelta(i ^ 1));
			}
			for (int i = tb; i > 1; i >>= 1) {
				value[i >> 1] = queryOperation(joinValueWithDelta(i), joinValueWithDelta(i ^ 1));
			}
		}
	}
}

class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;

	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream));
	}

	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 int nextInt() {
		return Integer.parseInt(next());
	}
}

