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

public class P380C
{
	static int most;
	public static void main(String[] args)
	{
		FastScanner scan = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		SegTree seg = new SegTree(scan.next().toCharArray());
		int m = scan.nextInt();
		for (int i = 0; i < m; i++)
		{
			int a = scan.nextInt();
			int b = scan.nextInt();
			pw.println(seg.getLongest(a, b));
		}
		pw.flush();
	}
	static class SegTree
	{
		int n;
		char[] arr;
		int[] left, right;
		int[] max, open, close;
		SegTree(char[] a)
		{
			n = a.length;
			arr = a;
			left = new int[4*n];
			right = new int[4*n];
			max = new int[4*n];
			open = new int[4*n];
			close = new int[4*n];
			init(1, 1, n);
		}
		public int getLongest(int a, int b)
		{
			int[] moc = getLongest(1, a, b);
			return moc[0];
		}
		private int[] getLongest(int i, int a, int b)
		{
			if (right[i] < a || left[i] > b)
				return new int[] {0, 0, 0};
			if (a <= left[i] && right[i] <= b)
				return new int[] {max[i], open[i], close[i]};
			int[] left = getLongest(2*i, a, b);
			int[] right = getLongest(2*i+1, a, b);
			int e = Math.min(left[1], right[2]);
			int m = left[0] + right[0] + 2*e;
			int o = left[1] + right[1] - e;
			int c = left[2] + right[2] - e;
			return new int[] {m, o, c};
		}
		private void init(int i, int a, int b)
		{
			most = Math.max(most, i);
			left[i] = a;
			right[i] = b;
			if (a == b)
			{
				if (arr[a-1] == '(')
					open[i] = 1;
				else
					close[i] = 1;
				return;
			}
			int m = (a+b)/2;
			init(2*i, a, m);
			init(2*i+1, m+1, b);
			int e = Math.min(open[2*i], close[2*i+1]);
			max[i] = max[2*i] + max[2*i+1] + 2*e;
			open[i] = open[2*i] + open[2*i+1] - e;
			close[i] = close[2*i] + close[2*i+1] - e;
		}
	}
	static class FastScanner
	{
		BufferedReader br;
		StringTokenizer st;

		public FastScanner()
		{
			try
			{
				br = new BufferedReader(new InputStreamReader(System.in));
				st = new StringTokenizer(br.readLine());
			} catch (Exception e)
			{
				e.printStackTrace();
			}
		}

		public String next()
		{
			if (st.hasMoreTokens())
				return st.nextToken();
			try
			{
				st = new StringTokenizer(br.readLine());
			} catch (Exception e)
			{
				e.printStackTrace();
			}
			return st.nextToken();
		}

		public int nextInt()
		{
			return Integer.parseInt(next());
		}

		public long nextLong()
		{
			return Long.parseLong(next());
		}

		public String nextLine()
		{
			String line = "";
			try
			{
				line = br.readLine();
			} catch (Exception e)
			{
				e.printStackTrace();
			}
			return line;
		}
	}
}
