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;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 6;
typedef struct node {
  int faltu_open;
  int faltu_closed;
  int len;
} node;
node tree[4 * maxn];
void build_max(int n);
int base, ql, qu;
int loga2(const int n) {
  int j = n, ct = 0, ct2 = 0;
  while (j) {
    if (!(j & 1)) ct2++;
    j /= 2;
    ct++;
  }
  return (ct2 == ct - 1) ? ct - 1 : ct;
}
void buildtree(string s) {
  int i, j, k, pos;
  int n = s.size();
  for (i = 0; i < n; i++) {
    pos = base + i;
    tree[pos].faltu_open = (s[i] == '(');
    tree[pos].faltu_closed = (s[i] == ')');
    tree[pos].len = 0;
  }
  build_max(n);
}
void build_max(int n) {
  int i;
  int curr = base >> 1;
  while (curr) {
    int ans = curr << 1;
    for (i = curr; i <= ans - 1; i++) {
      node p1, p2;
      p1 = tree[i * 2];
      p2 = tree[i * 2 + 1];
      int t = min(p1.faltu_open, p2.faltu_closed);
      tree[i].faltu_open = p1.faltu_open + p2.faltu_open - t;
      tree[i].faltu_closed = p1.faltu_closed + p2.faltu_closed - t;
      tree[i].len = p1.len + p2.len + 2 * t;
    }
    curr = curr >> 1;
  }
}
node query_max(int idx, int cl, int cu) {
  node tmp;
  tmp.faltu_open = tmp.faltu_closed = tmp.len = 0;
  if (ql > cu || qu < cl) return tmp;
  if (cl >= ql && cu <= qu)
    return tree[idx];
  else {
    int ans = idx << 1;
    int ans2 = (cl + cu) >> 1;
    node res1 = (query_max(ans, cl, ans2));
    node res2 = query_max(ans + 1, ans2 + 1, cu);
    int t = min(res1.faltu_open, res2.faltu_closed);
    node f;
    f.faltu_open = res1.faltu_open + res2.faltu_open - t;
    f.faltu_closed = res1.faltu_closed + res2.faltu_closed - t;
    f.len = res1.len + res2.len + 2 * t;
    return f;
  }
}
int main() {
  int t, i, j, ans = 0, q;
  string s;
  cin >> s;
  int k, st, end;
  int l = s.size();
  k = loga2(l);
  base = (1 << k);
  buildtree(s);
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &st);
    scanf("%d", &end);
    ql = st - 1;
    qu = end - 1;
    cout << query_max(1, 0, base - 1).len;
    puts("");
  }
  return 0;
}
