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

public class SerejaAndBrackets {

	static class Triple {
		int o, c, ans;
		
		Triple (int oo, int cc, int a){
			o = oo;
			c = cc;
			ans = a;
		}
	}
	
	static class SegmentTree {
		Triple []tree;
		int N;
		
		SegmentTree (int n){
			N = n;
			tree = new Triple[N << 2];
			build(1, 0, N - 1);
		}
		
		private int left(int p){
			return p << 1;
		}
		
		private int right(int p){
			return (p << 1) + 1;
		}
		
		private void build (int p, int L, int R){
			if(L == R){
				if(c[L] == '(')
					tree[p] = new Triple(1, 0, 0);
				else
					tree[p] = new Triple(0, 1, 0);
			}
			else {
				int mid = (L + R) >> 1, left = left(p), right = right(p);
				build(left, L, mid);
				build(right, mid + 1, R);
				tree[p] = merge(tree[left], tree[right]);
			}
		}
		
		private Triple merge (Triple t1, Triple t2){
			int min = Math.min(t1.o, t2.c);
			int o = t1.o + t2.o - min;
			int c = t1.c + t2.c - min;
			int ans = t1.ans + t2.ans + (min << 1);
			return new Triple(o, c, ans);
		}
		
		public int query (int i, int j){
			return query(1, 0, N - 1, i, j).ans;
		}
		
		private Triple query (int p, int L, int R, int i, int j){
			if(i > R || j < L)
				return new Triple(0, 0, 0);
			if(L >= i && R <= j)
				return tree[p];
			int mid = (L + R) >> 1, left = left(p), right = right(p);
			return merge(query(left, L, mid, i, j), query(right, mid + 1, R, i, j));
		}
	}
	
	static char [] c;
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		c = sc.nextLine().toCharArray();
		SegmentTree st = new SegmentTree(c.length);
		int q = sc.nextInt();
		while(q-- > 0){
			pw.println(st.query(sc.nextInt() - 1, sc.nextInt() - 1));
		}
		pw.close();
	}

	static class MyScanner {
		StringTokenizer st;
		BufferedReader br;

		public MyScanner(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 boolean ready() throws IOException {
			return br.ready();
		}
	}
}
