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

public class E {
    public static void main(String[] args) throws Exception {
        Parser in = new Parser(System.in);
        StringBuilder string = new StringBuilder();
        String brackets = in.next();
        
        int length = brackets.length();
        int[] open = new int[length];
        int[] closed = new int[length];
        
        for (int j = 0; j < length; j++) {
            char c = brackets.charAt(j);
            if (c == '(') open[j]++;
            if (c == ')') closed[j]++;
            if (j != 0) {
                open[j] += open[j-1];
                closed[j] += closed[j-1];
            }
        }       
        
        SegmentTreeBracket st = new SegmentTreeBracket(brackets, open, closed);
        
        int q = in.nextInt();
        
        for (int i = 0; i < q; i++) {
            int r = in.nextInt() - 1;
            int s = in.nextInt() - 1;
            string.append(st.solve(r, s) + "\n");
        }
        System.out.print(string);
    }
}

class SegmentTreeBracket {
    String brackets;
    int[] open, closed, s;
    int length;
    
    public SegmentTreeBracket(String brackets, int[] open, int[] closed) {
        this.brackets = brackets;
        this.open = open;
        this.closed = closed;
        this.length = brackets.length();
        this.s = new int[4 * length];
        build(1, 0, length - 1);
    }
    
    public int left(int p) { return p << 1; }
    public int right(int p) { return (p << 1) + 1; }
    
    public void build(int p, int left, int right) {
        if (left == right) s[p] = 0;
        else {
            build(left(p), left, (left + right) / 2);
            build(right(p), ((left + right) / 2) + 1, right);
            int p1 = s[left(p)];
            int p2 = s[right(p)];
            int op = open[(left + right) / 2];
            if (left > 0) op -= open[left - 1];         
            int cl = closed[right] - closed[(left + right) / 2];
            s[p] = p1 + p2 + 2*Math.min(op - p1 / 2, cl - p2 / 2);
        }
    }
    
    public int solve(int p, int left, int right, int i, int j) {
        if (i > right || j < left) return 0;
        if (left >= i && right <= j) return s[p];
        
        int p1 = solve(left(p), left, (left + right) / 2, i, j);
        int p2 = solve(right(p), ((left + right) / 2) + 1, right, i , j);
        
        int maxL = Math.max(i, left);
        int minR = Math.min(j,  right);
        
        int op = open[(left + right) / 2] - p1 / 2;         
        if (maxL > 0) op -= open[maxL - 1];
        int cl = closed[minR] - closed[(left + right) / 2] - p2 / 2;
        
        return p1 + p2 + 2*Math.min(Math.max(op, 0),Math.max(cl, 0));
    }
    
    public int solve(int i, int j) { return solve(1, 0, length - 1, i, j); }
}

class Parser
{
   final private int BUFFER_SIZE = 1 << 16;

   private DataInputStream din;
   private byte[] buffer;
   private int bufferPointer, bytesRead;

   public Parser(InputStream in)
   {
      din = new DataInputStream(in);
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
   }

   public long nextLong() throws Exception
   {
      long ret = 0;
      byte c = read();
      while (c <= ' ') c = read();
      boolean neg = c == '-';
      if (neg) c = read();
      do
      {
         ret = ret * 10 + c - '0';
         c = read();
      } while (c > ' ');
      if (neg) return -ret;
      return ret;
   }
   
   //reads in the next string
   public String next() throws Exception
   {
      StringBuilder ret = new StringBuilder();
      byte c = read();
      while (c <= ' ') c = read();
      do
      {
         ret = ret.append((char)c);
         c = read();
      } while (c > ' ');
      return ret.toString();
   }

   public int nextInt() throws Exception
   {
      int ret = 0;
      byte c = read();
      while (c <= ' ') c = read();
      boolean neg = c == '-';
      if (neg) c = read();
      do
      {
         ret = ret * 10 + c - '0';
         c = read();
      } while (c > ' ');
      if (neg) return -ret;
      return ret;
   }
   
   private void fillBuffer() throws Exception
   {
      bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
      if (bytesRead == -1) buffer[0] = -1;
   }

   private byte read() throws Exception
   {
      if (bufferPointer == bytesRead) fillBuffer();
      return buffer[bufferPointer++];
   }
}
