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


public class ProblemAA {

  
  static class Pair implements Comparable<Pair>{
    int idx;
    int value;
    @Override
    public int compareTo(Pair f) {
      if(value < f.value) return -1;
      return 1;
    }
  }
  
  public static void main(String args[]) throws Exception {
    
    Parserdoubt1223 in = new Parserdoubt1223(System.in);
    PrintWriter out = new PrintWriter(System.out);
   
    Stack<Integer> stack = new Stack<Integer>();
    
    String s = ")" + in.nextString();
    int n = s.length();
    int pair[] = new int[n];
    Arrays.fill(pair, -1);
    
    for (int i = 0; i < n; i++) {
      if(s.charAt(i) == '('){
        stack.add(i);
      }
      else if(stack.size() > 0){
        pair[i] = stack.pop();
      }
    }
    
//    System.out.println(Arrays.toString(pair));
    
    
    int m = in.nextInt();
    ArrayList<Integer> q[] = new ArrayList[1000100];
    for (int i = 0; i < q.length; i++) {
      q[i] = new ArrayList<Integer>();
    }
    
    int ll[] = new int[m];
    int rr[] = new int[m];
    for (int i = 0; i < m; i++) {
      ll[i] = in.nextInt();
      rr[i] = in.nextInt();
      q[rr[i]].add(ll[i]);
    }
    
    
    tree = new int[1000100];
    
    TreeMap<Long, Integer> map = new TreeMap<Long, Integer>();
    
    for (int i = 1; i < s.length(); i++) {
      if(pair[i] > -1){
        update(pair[i], 1);
      }
      
      for (int j = 0; j < q[i].size(); j++) {
        int left = q[i].get(j);
        long v = left * 10000000L + i;
        int aa = read(i) - read(left-1);
//        System.out.println("aaa");
//        System.out.println(v + " " + aa);
        map.put(v, aa);
      }
    }
    
    for (int i = 0; i < m; i++) {
      long v = ll[i] * 10000000L + rr[i];
      out.println(map.get(v)*2);
    }
    
    out.close();
  }
  
  static int tree[];
  
  static int read(int idx){
    int sum = 0;
    while(idx > 0){
      sum += tree[idx];
      idx -= idx & -idx;
    }
    return sum;
  }
 
  static void update(int idx, int value){
    while(idx < tree.length){
      tree[idx] += value;
      idx += idx & -idx;
    }
  }
}


class Parserdoubt1223
{
   final private int BUFFER_SIZE = 1 << 17;
 
   private DataInputStream din;
   private byte[] buffer;
   private int bufferPointer, bytesRead;
 
   public Parserdoubt1223(InputStream in)
   {
      din = new DataInputStream(in);
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
   }
   public String nextString() throws Exception
   {
       StringBuffer sb=new StringBuffer("");
       byte c = read();
       while (c <= ' ') c = read();
       do
       {
           sb.append((char)c);
           c=read();
       }while(c>' ');
       return sb.toString();
   }
   public char nextChar() throws Exception
   {
       byte c=read();
       while(c<=' ') c= read();
       return (char)c;
   }
   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;
   }
   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;
   }
   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++];
   }
} 
