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.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream.GetField;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.text.CollationKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	static class edge {
		long op;
		long cl;
		long v;

		public edge(long i, long j, long val) {
			op = i;
			cl = j;
			v = val;
		}

	}

	public static class SegmentTree { // 1-based DS, OOP

		int N; // the number of elements in the array as a power of 2 (i.e.
				// after
				// padding)
		int val = 0;
		int left = 0;
		int right = 0;
		long[] open, close, sTree, lazy, value;
		boolean[] array;

		public SegmentTree(boolean[] c)

		{
			array = c;
			N = array.length - 1;
			value = new long[N << 1];
			open = new long[N << 1]; // no. of nodes = 2*N - 1, we add one to
			close = new long[N << 1]; // cross out index zero
			lazy = new long[N << 1];

			build(1, 1, N);
		}

		public void build(int node, int b, int e) // O(n)
		{
			if (b == e) {
				if (array[b])
					open[node] = 1;
				else
					close[node] = 1;
			} else {
				int mid = b + e >> 1;
				build(node << 1, b, mid);
				build(node << 1 | 1, mid + 1, e);
				// sTree[node] = Math.min(sTree[node << 1], sTree[node << 1 |
				// 1]);
				long x = open[node << 1];
				long y = close[node << 1 | 1];
				if (x > y) {
					value[node] = value[node << 1] + value[node << 1 | 1] + y;
					open[node] = x - y + open[node << 1 | 1];
					close[node] = close[node << 1];
				} else {
					value[node] = value[node << 1] + value[node << 1 | 1] + x;
					open[node] = open[node << 1 | 1];
					close[node] = y - x + close[node << 1];
				}
			}
		}

		public void update_point(int index, int val) // O(log n)
		{
			index += N - 1;
			sTree[index] += val;
			while (index > 1) {
				index >>= 1;
				sTree[index] = sTree[index << 1] + sTree[index << 1 | 1];
			}
		}

		public void update_range(int i, int j, int val) // O(log n)
		{
			update_range(1, 1, N, i, j, val);
		}

		public void update_range(int node, int b, int e, int i, int j, int val) {
			if (i > e || j < b)
				return;
			if (b >= i && e <= j) {
				sTree[node] += val * 1l;
				lazy[node] += val * 1l;
			} else {
				int mid = b + e >> 1;
				propagate(node, b, mid, e);
				update_range(node << 1, b, mid, i, j, val);
				update_range(node << 1 | 1, mid + 1, e, i, j, val);
				sTree[node] = Math.min(sTree[node << 1], sTree[node << 1 | 1]);
			}
		}

		public void propagate(int node, int b, int mid, int e) {
			lazy[node << 1] += lazy[node];
			lazy[node << 1 | 1] += lazy[node];
			sTree[node << 1] += lazy[node];
			sTree[node << 1 | 1] += lazy[node];
			lazy[node] = 0;

		}

		public edge query(int i, int j)

		{

			return query(1, 1, N, i, j);

		}

		public edge query(int node, int b, int e, int i, int j) {
			if (i > e || j < b)
				return null;
			if (b >= i && e <= j)
				return new edge(open[node], close[node], value[node]);
			int mid = (b + e) >> 1;
			// propagate(node, b, mid, e);
			edge q1 = query(node << 1, b, mid, i, j);
			edge q2 = query(node << 1 | 1, mid + 1, e, i, j);
			if (q1 == null)
				return q2;

			if (q2 == null)
				return q1;

			long x = q1.op;
			long y = q2.cl;
			if (x > y)
				return new edge(x - y + q2.op, q1.cl, y + q1.v + q2.v);
			else
				return new edge(q2.op, q1.cl + y - x, x + q1.v + q2.v);

		}
	}

	static PrintWriter pw;

	public static void main(String[] args) throws IOException, InterruptedException {
		// FileWriter f = new FileWriter("C:\\Users\\Hp\\Desktop\\out.txt");
		// PrintWriter pw = new PrintWriter(f);
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int n = str.length();
		int N = 1;
		while (N < n)
			N <<= 1;
		boolean[] in = new boolean[N + 1];
		for (int i = 1; i <= n; i++)
			in[i] = str.charAt(i - 1) == '(';

		int m = sc.nextInt();
		SegmentTree sg = new SegmentTree(in);
		for (int i = 0; i < m; i++) {
			pw.println(2 *( sg.query(sc.nextInt(), sc.nextInt())).v);
		}
		pw.close();

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

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

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}
