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

public class cf380c {
  static FastIO in = new FastIO(), out = in;

  static char[] v;
  public static void main(String[] args) {
    v = in.next().trim().toCharArray();
    int n = v.length;
    IntervalTree it = new IntervalTree(n);
    int m = in.nextInt();
    for(int i=0; i<m; i++) {
      out.println(it.query(in.nextInt()-1, in.nextInt()-1));
    }
    out.close();
  }
  
  static class IntervalTree {
    static final int NULL_VALUE = 0; // change this
    int[] lo, hi;
    int[][] data;
    static int[] ZERO = new int[3];
    public IntervalTree(int N) {
      int size = (Integer.highestOneBit(N)<<2)+1;
      lo = new int[size];
      hi = new int[size];
      data = new int[size][];
      init(1, 0, N - 1);
    }
    public int query(int l, int h) {
      return query(1,l,h)[0];
    }
    private int[] aggregate(int[] left, int[] right) {
      int extra = Math.min(left[1], right[2]);
      return new int[]{
          left[0] + right[0] + 2*extra,
          left[1] + right[1] - extra,
          left[2] + right[2] - extra
      };
    } // change this
    private void init(int i, int l, int h) {
      lo[i] = l; hi[i] = h;
      int m = (l + h) / 2;
      if(l==h) {
        data[i] = new int[3];
        if(v[l] == '(')
          data[i][1] = 1;
        else
          data[i][2] = 1;
        return;
      }
      init(2 * i, l, m);
      init(2 * i + 1, m + 1, h);
      data[i] = aggregate(data[2*i],data[2*i+1]);
    }
    private int[] query(int i, int l, int h) {
      if (h < lo[i] || hi[i] < l) {
        return ZERO;
      }
      if(l <= lo[i] && hi[i] <= h) {
        return data[i];
      }
      return aggregate(query(2*i,l,h), query(2*i+1,l,h));
    }
  }


  static class FastIO extends PrintWriter {
    BufferedReader br;
    StringTokenizer st;

    public FastIO() {
      this(System.in, System.out);
    }

    public FastIO(InputStream in, OutputStream out) {
      super(new BufferedWriter(new OutputStreamWriter(out)));
      br = new BufferedReader(new InputStreamReader(in));
      scanLine();
    }

    public void scanLine() {
      try {
        st = new StringTokenizer(br.readLine().trim());
      } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
      }
    }

    public int numTokens() {
      if (!st.hasMoreTokens()) {
        scanLine();
        return numTokens();
      }
      return st.countTokens();
    }

    public String next() {
      if (!st.hasMoreTokens()) {
        scanLine();
        return next();
      }
      return st.nextToken();
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

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

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