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

public class SerejaBrackets {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		String br = sc.nextLine();
		int n = br.length();
		int N = (int) Math.pow(2, Math.ceil(Math.log(n)/Math.log(2)));
		Vertex a[] = new Vertex[N+1];
		for(int i=0; i<n; i++)
		{
			char b = br.charAt(i);
			if(b == '(')
			{
				a[i+1] = new Vertex(1,0,0);
			}
			else
			{
				a[i+1] = new Vertex(0,1,0);
			}
		}
		for(int i = n+1; i<=N; i++)
		{
			a[i] = new Vertex(0,0,0);
		}
		
		SegmentTree tree = new SegmentTree(a);
		int m = sc.nextInt();
		PrintWriter out = new PrintWriter(System.out);
		for(int i=0; i<m; i++)
		{
			int l = sc.nextInt();
			int r = sc.nextInt();
			out.println(tree.query(l,r).max);
		}
		out.flush();

	}
	static class Vertex
	{
		int o;
		int c;
		int max;
		
		public Vertex(int x, int y, int z)
		{
			o = x;
			c = y;
			max = z;
		}
	}
	static class SegmentTree
	{
		int N; 			//the number of elements in the array as a multipls of 2 (i.e. after padding)
		Vertex[] array, sTree, lazy;
		
		SegmentTree(Vertex[] in)		
		{
			array = in; N = in.length - 1;
			sTree = new Vertex[N<<1];		//no. of nodes = 2*N - 1, we add one to cross out index zero
			build(1,1,N);
		}
		
		void build(int node, int b, int e)	// O(n)
		{
			if(b == e)					
				sTree[node] = array[b];
			else						
			{
				build(node<<1,b,(b+e)/2);
				build((node<<1)+1,(b+e)/2+1,e);
				int op = sTree[node<<1].o;
				int cl = sTree[(node<<1)+1].c;
				int lo = sTree[node<<1].max + sTree[(node<<1)+1].max;
				sTree[node] = new Vertex(sTree[(node<<1)+1].o + op - Math.min(op, cl), sTree[(node<<1)].c + cl - Math.min(op, cl),Math.min(op, cl)*2 + lo);
			}
		}
		
		
		
		
		
		
		
		
		Vertex query(int i, int j)
		{
			return query(1,1,N,i,j);
		}
		
		Vertex query(int node, int b, int e, int i, int j)	// O(log n)
		{
			if(i>e || j <b)
				return new Vertex(0,0,0);		
			if(b>= i && e <= j)
				return sTree[node];
			
			Vertex left = query(node<<1,b,(b+e)/2,i,j);
			Vertex right = query((node<<1)+1,(b+e)/2+1,e,i,j);
			
			int op = left.o;
			int cl = right.c;
			int lo = left.max + right.max;
			
			return new Vertex(op + right.o - Math.min(op, cl), left.c + cl - Math.min(op, cl),Math.min(op, cl)*2 + lo);
				
					
		}
		
//		int query(int i, int j)
//		{
//			return query(1,1,N,i,j);
//		}
//		
//		int query(int node, int b, int e, int i, int j)	// O(log n)
//		{
//			if(i>e || j <b)
//				return 0;		
//			if(b>= i && e <= j)
//				return sTree[node].max;
//			
//			return query(node<<1,b,(b+e)/2,i,j) + query((node<<1)+1,(b+e)/2+1,e,i,j);	
//					
//		}
	}
	
	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner(FileReader f) {
			br = new BufferedReader(f);
		}

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

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

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

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

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

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

}
