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 «()(())(())».
/*
 * 
 * @Author  Ajudiya_13(Bhargav Girdharbhai Ajudiya)
 * Dhirubhai Ambani Institute of Information And Communication Technology 
 * 
 */


import java.util.*;
import java.io.*;
import java.lang.*;

public class Code213
{
	static class SegmentTree
	{
		triplet st[];
		
		SegmentTree(triplet[]a , int n)
		{
			int x = (int)Math.ceil((Math.log(n)/Math.log(2)));
			int Max_Size = 2*(int)(Math.pow(2, x))-1;
			//System.out.println(Max_Size);
			st = new triplet[Max_Size];
			constructSegmentTreeUtil(a,0,n-1,0);
		}
		
		int getMid(int start,int end)
		{
			return (start+end)/2;
		}
		
		triplet constructSegmentTreeUtil(triplet[] a,int ss,int se,int si)
		{
			if(ss==se)
			{
				st[si] = a[ss];
				return st[si];
			}
			
			int mid = getMid(ss, se);
			triplet left = constructSegmentTreeUtil(a, ss, mid, 2*si+1);
			triplet right = constructSegmentTreeUtil(a, mid+1, se, 2*si+2);
			
			int t = Math.min(left.y, right.z);
			st[si] = new triplet(left.x+right.x+t,left.y+right.y-t,left.z+right.z-t);
			return st[si];
		}
		
		triplet getSum(int n,int qs,int qe)
		{
			if(qs<0 || qe>n-1 || qs>qe)
				return new triplet(-1,-1,-1);
			
			return getSumUtil(0,n-1,qs,qe,0);
		}
		
		triplet getSumUtil(int ss,int se,int qs,int qe,int si)
		{
			if(qs<=ss && qe>=se)
				return st[si];
			
			if(qs>se || qe<ss)
				return new triplet(0,0,0);
			
			int mid = getMid(ss, se);
			
			triplet left = getSumUtil(ss, mid, qs, qe, 2*si+1);
			triplet right = getSumUtil(mid+1, se, qs, qe, 2*si+2);
			
			int t = Math.min(left.y, right.z);
			return new triplet(left.x+right.x+t,left.y+right.y-t,left.z+right.z-t);
		}
	}
	
	public static void main(String[] args)
	{
		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);
	
		String s = in.nextLine();
		int n = s.length();
		//System.out.println(n);
		triplet[] a = new triplet[n];
		for(int i=0;i<n;i++)
		{
			if(s.charAt(i)=='(')
				a[i] = new triplet(0,1,0);
			else
				a[i] = new triplet(0,0,1);
		}
		SegmentTree segtree = new SegmentTree(a, n);
		int query = in.nextInt();
		for(int q=0;q<query;q++)
		{
			triplet p = segtree.getSum(n, in.nextInt()-1,in.nextInt()-1);
			pw.println(p.x<<1);
		}
		pw.flush();
		pw.close();
	}
	
	static class InputReader {
		 
		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;
 
		public InputReader(InputStream stream) {
			this.stream = stream;
		}
 
		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}
 
		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}
 
		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}
 
		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}
 
		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}
 
		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}
 
		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
 
		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}
	
	static class triplet 
	{
		Integer x, y, z;
		triplet(int x,int y,int z)
		{
			this.x=x;
			this.y=y;
			this.z=z;
		}
	}
}