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 data {
  long long ans, x, y;
};
data tree[2098149];
long long a[1000100];
char s[1000100];
void ini(long long s, long long e, long long node) {
  if (s == e) {
    tree[node].ans = tree[node].x = tree[node].y = 0;
    if (a[s] == 1)
      tree[node].x = 1;
    else
      tree[node].y = 1;
    return;
  }
  long long lft = node << 1, rht = (node << 1) | 1, mid = (s + e) >> 1;
  ini(s, mid, lft);
  ini(mid + 1, e, rht);
  tree[node].ans = tree[lft].ans + tree[rht].ans;
  tree[node].ans += min(tree[lft].x, tree[rht].y);
  tree[node].x = tree[rht].x;
  tree[node].y = tree[lft].y;
  if (tree[lft].x > tree[rht].y)
    tree[node].x += tree[lft].x - tree[rht].y;
  else
    tree[node].y += tree[rht].y - tree[lft].x;
  return;
}
long long ix;
long long S, E;
data N;
data qry(long long s, long long e, long long node) {
  if (S <= s && e <= E) return tree[node];
  if (s > E || S > e) return N;
  long long lft = node << 1, rht = (node << 1) | 1, mid = (s + e) >> 1;
  data xx = qry(s, mid, lft);
  data yy = qry(mid + 1, e, rht);
  data ret;
  ret.ans = xx.ans + yy.ans;
  ret.ans += min(xx.x, yy.y);
  ret.x = yy.x;
  ret.y = xx.y;
  if (xx.x > yy.y)
    ret.x += xx.x - yy.y;
  else
    ret.y += yy.y - xx.x;
  return ret;
}
int main() {
  N.ans = N.x = N.y = 0;
  scanf("%s", s);
  long long len = strlen(s);
  for (long long i = 0; i < len; i++) a[i + 1] = (s[i] == '(') ? 1 : 0;
  ini(1, len, 1);
  long long m;
  char c;
  scanf("%lld", &m);
  while (m--) {
    scanf("%lld %lld", &S, &E);
    data aaa = qry(1, len, 1);
    printf("%lld\n", aaa.ans * 2);
  }
  return 0;
}
