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 «()(())(())».
//package round641;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class a2oj {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
	
	
	void solve()
	{
		String st = ns();
		int n  =st.length();
		st = " "+st;
		seg = new pair[6*n+1];
		for(int i=0;i<=6*n;i++){
			seg[i] = new pair(0,0,0);  
		}
		build(1, n, 1, n, st, 1);
		
		int q = ni();
		while(q-->0){
			int l = ni();
			int r = ni();
			pair ans = query(l, r, 1, n, 1);
			out.println(ans.balanced*2);
		}	
	}
	
	public static pair query(int x, int y, int l, int r, int index){
		
		if(l>y || r<x)
			return new pair(0,0,0);
		if(l>=x && r<=y){
			return new pair(seg[index].open, seg[index].close,seg[index].balanced);
		}
		
		int mid = (l+r)/2;
		pair val1 = query(x, y, l, mid, 2*index+1);
		pair val2 = query(x, y, mid+1, r, 2*index+2);
		int balanced = val1.balanced+val2.balanced;
		int next_balance = Math.min(val1.open, val2.close);
		balanced += next_balance;
		int open = val1.open - next_balance + val2.open;
		int close = val1.close + val2.close - next_balance;
		return new pair(open, close, balanced);
	}
	
	public static void build(int x, int y, int l, int r, String st, int index){
		
		if(l>y || r<x){
			return;
		}
		
		
		if(l==r){
			if(st.charAt(l)=='(')
				seg[index].open+=1;
			else if(st.charAt(l)==')')
				seg[index].close+=1;
			return;
		}
		
		int mid = (l+r)/2;
		build(x, y, l, mid, st, 2*index+1);
		build(x, y, mid+1, r, st, 2*index+2);
		seg[index].balanced = seg[2*index+1].balanced + seg[2*index+2].balanced;
		
		int next_balance = Math.min(seg[2*index+1].open , seg[2*index+2].close);
		
		seg[index].balanced  += next_balance;
		
		seg[index].open = seg[2*index+1].open - next_balance + seg[2*index+2].open;
		seg[index].close = seg[2*index+1].close + seg[2*index+2].close - next_balance;
	}
	
	static pair seg[];
	
	static class pair{
		int open;
		int close;
		int balanced;
		pair(int open, int close, int balanced){
			this.open = open;
			this.close = close;
			this.balanced = balanced;
		}
	}
	
	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}
	
	public static void main(String[] args) throws Exception { new a2oj().run(); }
	
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;
	
	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }
	
	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
