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 «()(())(())».
#include <bits/stdc++.h>
using namespace std;
struct node {
  int a, b, c;
  node() { a = b = c = 0; }
};
string str;
node st[3000005];
int n, l, r;
node query(int ss, int se, int qs, int qe, int si) {
  if (qs <= ss && qe >= se) return st[si];
  if (se < qs || ss > qe) {
    node y;
    y.a = y.b = y.c = 0;
    return y;
  }
  int mid = ss + (se - ss) / 2;
  node z1 = query(ss, mid, qs, qe, 2 * si + 1);
  node z2 = query(mid + 1, se, qs, qe, 2 * si + 2);
  node z3;
  int t = min(z1.b, z2.c);
  z3.a = z1.a + z2.a + 2 * t;
  z3.b = z1.b + z2.b - t;
  z3.c = z1.c + z2.c - t;
  return z3;
}
void constructTree(int ss, int se, int si) {
  if (ss == se) {
    st[si].a = 0;
    if (str[ss] == '(')
      st[si].b = 1;
    else
      st[si].c = 1;
    return;
  }
  int mid = ss + (se - ss) / 2;
  constructTree(ss, mid, si * 2 + 1);
  constructTree(mid + 1, se, si * 2 + 2);
  int t = min(st[si * 2 + 1].b, st[si * 2 + 2].c);
  st[si].a = st[si * 2 + 1].a + st[si * 2 + 2].a + 2 * t;
  st[si].b = st[si * 2 + 1].b + st[si * 2 + 2].b - t;
  st[si].c = st[si * 2 + 1].c + st[si * 2 + 2].c - t;
  return;
}
int main() {
  int q;
  cin >> str;
  n = str.size();
  constructTree(0, n - 1, 0);
  cin >> q;
  while (q--) {
    for (int i = 0; i < n; i++) {
    }
    cin >> l >> r;
    l--;
    r--;
    node ans = query(0, n - 1, l, r, 0);
    cout << ans.a << endl;
  }
  return 0;
}
