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.math.*;
import java.util.*;

import static java.util.Arrays.*;

public class C {
	private static final int mod = (int)1e9+7;

	final Random random = new Random(0);
	final IOFast io = new IOFast();
	
	int[] height(char[] c, char bra, char cket) {
		int[] h = new int[c.length+1];
		for(int i = 0; i < c.length; i++) {
			if(c[i] == cket) {
				h[i+1] = h[i];
				if(i == 0 || c[i-1] == cket) h[i+1]--;
				h[i+1] = Math.max(h[i+1], -1);
			}
			else {
				h[i+1] = h[i];
				if(i > 0 && c[i-1] == bra) h[i+1]++;
				h[i+1] = Math.max(h[i+1], 0);
			}
		}
		return Arrays.copyOfRange(h, 1, h.length);
	}
	
	void reverse(char[] cs) {
		for(int i = 0; i < cs.length / 2; i++) {
			char c = cs[i];
			cs[i] = cs[cs.length-1-i];
			cs[cs.length-1-i] = c;
		}
	}
	
	void reverse(int[] cs) {
		for(int i = 0; i < cs.length / 2; i++) {
			int c = cs[i];
			cs[i] = cs[cs.length-1-i];
			cs[cs.length-1-i] = c;
		}
	}
	
	public void run() throws IOException {
		char[] cs = io.next();
		int[] h = height(cs, '(', ')');
		int[] prev = new int[cs.length];
		int[] match = new int[cs.length];
		for(int i = 0; i < cs.length; i++) {
			match[i] = -1;
			if(cs[i] == '(') {
				prev[h[i]] = i;
			}
			else if(h[i] >= 0) {
				match[i] = prev[h[i]];
			}
		}
		
//		int[] m1 = getMinMatch(cs, '(', ')');
//		System.err.println(Arrays.toString(match));
		BIT bit = new BIT(cs.length);
		
		long n = cs.length;
		int m = io.nextInt();
		long[] q = new long[m];
		for(int i = 0; i < m; i++) {
			int l = io.nextInt() - 1;
			int r = io.nextInt() - 1;
			q[i] = (r * n + l) * m + i;
		}
		radixSort(q);
		int[] ans = new int[m];
		for(int i = 0, vr = 0; i < m; i++) {
			int idx = (int)(q[i] % m);
			int l = (int)(q[i] / m % n);
			int r = (int)(q[i] / m / n) + 1;
			
			for(; vr < r; vr++) {
				if(match[vr] != -1) {
					bit.add(match[vr] + 1, 1);
				}
			}
			ans[idx] = bit.sum(l, r) * 2;
		}
		for(int x : ans) io.out.println(x);
	}
	
	static
	class BIT {
		final int n;
		final int[] bit;

		public BIT(int size) {
			n = size;
			bit = new int[n + 1];
		}
		
		public void clear() { Arrays.fill(bit, 0); }

		public int lowerBoundIndex(int x) {
			int i = Integer.highestOneBit(bit.length - 1);
			int sum = 0;
			int cur = 0;
			int ans = Integer.MAX_VALUE;
			int ansIndex = 0;
			for(; i > 0; i >>= 1) {
				cur ^= i;
				if(cur < bit.length && sum + bit[cur] < x) {
					sum += bit[cur];
				}
				else {
					if(cur < bit.length && ans > sum + bit[cur]) {
						ans = sum + bit[cur];
						ansIndex = cur;
					}
					
					cur ^= i;
				}
			}
			return ansIndex;
		}
		
		public int lowerBound(int x) {
			int i = Integer.highestOneBit(bit.length - 1);
			int sum = 0;
			int cur = 0;
			int ans = Integer.MAX_VALUE;
			int ansIndex = 0;
			for(; i > 0; i >>= 1) {
				cur ^= i;
				if(cur < bit.length && sum + bit[cur] < x) {
					sum += bit[cur];
				}
				else {
					if(cur < bit.length && ans > sum + bit[cur]) {
						ans = sum + bit[cur];
						ansIndex = cur;
					}
					
					cur ^= i;
				}
			}
			return ans;
		}

		// [i, j)
		public int sum(int i, int j) {
			return sum(j) - sum(i);
		}

		public int sum(int i) {
			int res = 0;
			for (; i > 0; i -= i & -i) {
				res += bit[i];
//				while(res >= mod) res -= mod;
			}
			return res;
		}

		// 1<=i<=n
		public void add(int i, int x) {
			if(i == 0) throw new RuntimeException();
			for (; i <= n; i += i & -i) {
				bit[i] += x;
//				while(bit[i] >= mod) bit[i] -= mod;
			}
		}
	}



	// ()() -> [-1,0,-1,0]
	static int[] getMaxMatch(char[] cs, final char br, final char ck) {
		int n = cs.length;
		int[] prev = new int[n];
		
		prev[0] = -1;
		for(int i = 1; i < n; i++) {
			char a = cs[i-1], b = cs[i];
			prev[i] = -1;
			if(a == br) {
				if(b == ck) {
					prev[i] = i == 1 || prev[i-2] == -1 ? i - 1 : prev[i-2];
				}
			}
			else if(b == ck) {
				int p = prev[i-1];
				if(p > 0 && cs[p - 1] == br) {
					prev[i] = p - 2 > 0 && prev[p - 2] != -1 ? prev[p - 2] : p - 1;
				}
			}
		}
		
		return prev;
	}
	
	static int[] getMinMatch(char[] cs, final char br, final char ck) {
		int n = cs.length;
		int[] prev = new int[n];
		
		prev[0] = -1;
		for(int i = 1; i < n; i++) {
			char a = cs[i-1], b = cs[i];
			prev[i] = -1;
			if(a == br) {
				if(b == ck) {
					prev[i] = i - 1;
				}
			}
			else if(b == ck) {
				int p = prev[i-1];
				if(p > 0 && cs[p - 1] == br) {
					prev[i] = p - 1;
				}
			}
		}
		
		return prev;
	}


	static void radixSort(int[] xs) {
		int[] cnt = new int[(1<<16)+1];
		int[] ys = new int[xs.length];
		
		for(int j = 0; j <= 16; j += 16) {
			Arrays.fill(cnt, 0);
			for(int x : xs) { cnt[(x>>j&0xFFFF)+1]++; }
			for(int i = 1; i < cnt.length; i++) { cnt[i] += cnt[i-1]; }
			for(int x : xs) { ys[cnt[x>>j&0xFFFF]++] = x; }
			{ final int[] t = xs; xs = ys; ys = t; }
		}
	}
	
	static void radixSort(long[] xs) {
		int[] cnt = new int[(1<<16)+1];
		long[] ys = new long[xs.length];
		
		for(int j = 0; j <= 48; j += 16) {
			Arrays.fill(cnt, 0);
			for(long x : xs) { cnt[(int)(x>>j&0xFFFF)+1]++; }
			for(int i = 1; i < cnt.length; i++) { cnt[i] += cnt[i-1]; }
			for(long x : xs) { ys[cnt[(int)(x>>j&0xFFFF)]++] = x; }
			{ final long[] t = xs; xs = ys; ys = t; }
		}
	}
	

	static void arrayIntSort(int[][] x, int... keys) {
		Arrays.sort(x, new ArrayIntsComparator(keys));
	}
	
	static class ArrayIntsComparator implements Comparator<int[]> {
		final int[] KEY;
		
		public ArrayIntsComparator(int... key) {
			KEY = key;
		}
		
		@Override
		public int compare(int[] o1, int[] o2) {
			for(int k : KEY) if(o1[k] != o2[k]) return o1[k] - o2[k];
			return 0;
		}
	}
	
	static class ArrayIntComparator implements Comparator<int[]> {
		final int KEY;
		
		public ArrayIntComparator(int key) {
			KEY = key;
		}
		
		@Override
		public int compare(int[] o1, int[] o2) {
			return o1[KEY] - o2[KEY];
		}
	}
	
	
	void main() throws IOException {
		//		IOFast.setFileIO("rle-size.in", "rle-size.out");
		try {
			run();
		}
		catch (EndOfFileRuntimeException e) { }
		io.out.flush();
	}

	public static void main(String[] args) throws IOException {
		new C().main();
	}
	
	static class EndOfFileRuntimeException extends RuntimeException {
		private static final long serialVersionUID = -8565341110209207657L; }

	static
	public class IOFast {
		private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		private PrintWriter out = new PrintWriter(System.out);

		void setFileIO(String ins, String outs) throws IOException {
			in = new BufferedReader(new FileReader(ins));
			out = new PrintWriter(new FileWriter(outs));
		}

		//		private static final int BUFFER_SIZE = 50 * 200000;
		private static int pos, readLen;
		private static final char[] buffer = new char[1024 * 8];
		private static char[] str = new char[500*8*2];
		private static boolean[] isDigit = new boolean[256];
		private static boolean[] isSpace = new boolean[256];
		private static boolean[] isLineSep = new boolean[256];

		static {
			for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; }
			isDigit['-'] = true;
			isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true;
			isLineSep['\r'] = isLineSep['\n'] = true;
		}

		public int read() throws IOException {
			if(pos >= readLen) {
				pos = 0;
				readLen = in.read(buffer);
				if(readLen <= 0) { throw new EndOfFileRuntimeException(); }
			}
			return buffer[pos++];
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(nextString());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(nextString());
		}

		public char nextChar() throws IOException {
			while(true) {
				final int c = read();
				if(!isSpace[c]) { return (char)c; }
			}
		}
		
		int reads(int len, boolean[] accept) throws IOException {
			try {
				while(true) {
					final int c = read();
					if(accept[c]) { break; }
					
					if(str.length == len) {
						char[] rep = new char[str.length * 3 / 2];
						System.arraycopy(str, 0, rep, 0, str.length);
						str = rep;
					}
					
					str[len++] = (char)c;
				}
			}
			catch(EndOfFileRuntimeException e) { ; }
			
			return len;
		}
		
		int reads(char[] cs, int len, boolean[] accept) throws IOException {
			try {
				while(true) {
					final int c = read();
					if(accept[c]) { break; }
					cs[len++] = (char)c;
				}
			}
			catch(EndOfFileRuntimeException e) { ; }
			
			return len;
		}

		public char[] nextLine() throws IOException {
			int len = 0;
			str[len++] = nextChar();
			len = reads(len, isLineSep);
			
			try {
				if(str[len-1] == '\r') { len--; read(); }
			}
			catch(EndOfFileRuntimeException e) { ; }
			
			return Arrays.copyOf(str, len);
		}

		public String nextString() throws IOException {
			return new String(next());
		}

		public char[] next() throws IOException {
			int len = 0;
			str[len++] = nextChar();
			len = reads(len, isSpace);
			return Arrays.copyOf(str, len);
		}

		public int next(char[] cs) throws IOException {
			int len = 0;
			cs[len++] = nextChar();
			len = reads(cs, len, isSpace);
			return len;
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(nextString());
		}

		public long[] nextLongArray(final int n) throws IOException {
			final long[] res = new long[n];
			for(int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public int[] nextIntArray(final int n) throws IOException {
			final int[] res = new int[n];
			for(int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[][] nextIntArray2D(final int n, final int k) throws IOException {
			final int[][] res = new int[n][];
			for(int i = 0; i < n; i++) {
				res[i] = nextIntArray(k);
			}
			return res;
		}

		public int[][] nextIntArray2DWithIndex(final int n, final int k) throws IOException {
			final int[][] res = new int[n][k+1];
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < k; j++) {
					res[i][j] = nextInt();
				}
				res[i][k] = i;
			}
			return res;
		}

		public double[] nextDoubleArray(final int n) throws IOException {
			final double[] res = new double[n];
			for(int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

	}

}
