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;
int op[1000010], cl[1000010], ans[1000010], arr[1000010];
int tree[4000010];
void build_tree(int node, int a, int b) {
  if (a > b) return;
  if (a == b) {
    tree[node] = arr[a];
    return;
  }
  build_tree(node * 2, a, (a + b) / 2);
  build_tree(node * 2 + 1, 1 + (a + b) / 2, b);
  tree[node] = min(tree[node * 2], tree[node * 2 + 1]);
}
int query_tree(int node, int a, int b, int i, int j) {
  if (a > b || a > j || b < i) return INT_MAX;
  if (a >= i && b <= j) return tree[node];
  int q1 = query_tree(node * 2, a, (a + b) / 2, i, j);
  int q2 = query_tree(1 + node * 2, 1 + (a + b) / 2, b, i, j);
  int res = min(q1, q2);
  return res;
}
int main() {
  string s;
  int q, x, y, len, i, tmp, fl = 0;
  cin >> s;
  len = s.length();
  op[0] = 0;
  cl[0] = 0;
  ans[0] = 0;
  tmp = 0;
  arr[0] = 0;
  for (i = 0; i < len; i++) {
    ans[i + 1] = ans[i];
    op[i + 1] = op[i];
    cl[i + 1] = cl[i];
    if (s[i] == '(') {
      op[i + 1]++;
      tmp++;
    } else {
      cl[i + 1]++;
      if (tmp != 0) {
        ans[i + 1]++;
        tmp--;
      }
    }
    arr[i + 1] = tmp;
  }
  build_tree(1, 0, len);
  cin >> q;
  while (q--) {
    cin >> x >> y;
    int ans_range = ans[y] - ans[x - 1];
    int quer = query_tree(1, 0, len, x, y);
    int output = ans_range - max(0, arr[x - 1] - quer);
    cout << (output * 2) << endl;
  }
  return 0;
}
