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;
long long n;
void buildtree(long long tree[][3], string &second, long long index,
               long long start, long long end) {
  if (start > end) return;
  if (start == end) {
    if (second[start] == '(')
      tree[index][0]++;
    else
      tree[index][1]++;
    return;
  }
  long long mid = (start + end) / 2;
  buildtree(tree, second, 2 * index, start, mid);
  buildtree(tree, second, 2 * index + 1, mid + 1, end);
  long long y = min(tree[2 * index][0], tree[2 * index + 1][1]);
  tree[index][0] = (tree[2 * index][0] + tree[2 * index + 1][0] - y);
  tree[index][1] = (tree[2 * index][1] + tree[2 * index + 1][1] - y);
  tree[index][2] = (tree[2 * index][2] + tree[2 * index + 1][2] + y);
  return;
}
tuple<long long, long long, long long> query(long long tree[][3],
                                             long long index, long long second,
                                             long long e, long long qs,
                                             long long qe) {
  if (qs > e || second > qe)
    return make_tuple((long long)0, (long long)0, (long long)0);
  if (qe >= e && second >= qs) {
    return make_tuple(tree[index][0], tree[index][1], tree[index][2]);
  }
  long long mid = (second + e) / 2;
  tuple<long long, long long, long long> left =
      query(tree, 2 * index, second, mid, qs, qe);
  tuple<long long, long long, long long> right =
      query(tree, 2 * index + 1, mid + 1, e, qs, qe);
  long long x1 = get<0>(left);
  long long x2 = get<1>(left);
  long long x3 = get<2>(left);
  long long y1 = get<0>(right);
  long long y2 = get<1>(right);
  long long y3 = get<2>(right);
  long long t = min(x1, y2);
  long long a1 = x1 + y1 - t;
  long long b1 = x2 + y2 - t;
  long long c1 = x3 + y3 + t;
  return make_tuple(a1, b1, c1);
}
void solve() {
  string second;
  cin >> second;
  n = second.size();
  long long tree[4 * n + 1][3];
  memset(tree, 0, sizeof(tree));
  buildtree(tree, second, 1, 0, n - 1);
  long long q;
  cin >> q;
  while (q--) {
    long long x, y;
    cin >> x >> y;
    x--, y--;
    tuple<long long, long long, long long> ans = query(tree, 1, 0, n - 1, x, y);
    cout << 2 * (get<2>(ans)) << "\n";
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t;
  t = 1;
  while (t--) solve();
  return 0;
}
