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 SerejaAndBrackets {

	public static void main(String[] args) throws Exception{
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		
		String s = f.readLine();
		int m = Integer.parseInt(f.readLine());
		
		SegmentTree tree = new SegmentTree(s.length(),s);
		
		for(int i = 0;i<m;i++) {
			StringTokenizer st = new StringTokenizer(f.readLine());
			int x = Integer.parseInt(st.nextToken()) - 1;
			int y = Integer.parseInt(st.nextToken()) - 1;
			System.out.println(tree.max(x,y) * 2);
		}
	}
	

	static class SegmentTree{
		int n;
		int[] lo, hi, x,y,z;
		String s;
		public SegmentTree(int n, String s) {
			this.n = n;
			lo = new int[4*n+1];
			hi = new int[4*n+1];
			x = new int[4*n+1];
			y = new int[4*n+1];
			z = new int[4*n+1];
			//in = new int[n];
			this.s = s;
			
			init(1,0,n-1);
		}
		
		void update(int i) {
			int X = Math.min(y[2*i], z[2*i+1]);
			x[i] = x[2*i] + x[2*i+1] + X;
			y[i] = y[2*i] + y[2*i+1] - X;
			z[i] = z[2*i] + z[2*i+1] - X;
		}
		/*
		void increment(int i, int a, int b, int type) {
			if(b < lo[i]  || hi[i] < a) {
				return;
			}
			
			if(a <= lo[i] && hi[i] <= b) {
				if(type == 1) {
					y[i] ++;
				}
				else {
					z[i] ++;
				}
				return;
			}
			
			increment(2*i,a,b,type);
			increment(2*i+1,a,b,type);
			
			update(i);
		}
*/
		void init(int i, int a, int b) {
			lo[i] = a;
			hi[i] = b;
			
			if(a == b) {
				if(s.charAt(a) == '(') {
					y[i] ++;
				}
				else {
					z[i] ++;
				}
				return;
			}
			
			int m = (a+b)/2;
			init(2*i,a,m);
			init(2*i+1,m+1,b);
			
			update(i);
		}

		public int max(int i, int j) {
			return max(1,i,j).x;
		}
		
		Triplet max(int i, int a, int b) {
			if(b < lo[i] || hi[i] < a) {
				return new Triplet(0,0,0);
			}
			if(a <= lo[i] && hi[i] <= b) {
				return new Triplet(x[i],y[i],z[i]);
			}

			Triplet mL = max(2*i,a,b);
			Triplet mR = max(2*i+1,a,b);
			
			int X = Math.min(mL.y, mR.z);
			
			Triplet ret = new Triplet(0,0,0);
			
			ret.x = mL.x + mR.x + X;
			ret.y = mL.y + mR.y - X;
			ret.z = mL.z + mR.z - X;
			
			return ret;
		}
	}
	
	static class Triplet{
		int x, y, z;
		Triplet(int x, int y, int z){
			this.x = x;
			this.y = y;
			this.z = z;
		}
	}
	

}
