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;
string s;
struct node {
  int left = 0, right = 0, cnt = 0;
} tree[3 * 1000007];
void init(int n, int b, int e) {
  if (b == e) {
    if (s[b] == ')')
      tree[n].right++;
    else
      tree[n].left++;
    tree[n].cnt = 0;
    return;
  }
  int mid = (b + e) >> 1;
  int l = n << 1;
  int r = l + 1;
  init(l, b, mid);
  init(r, mid + 1, e);
  tree[n].cnt =
      2 * (min(tree[r].right, tree[l].left)) + tree[r].cnt + tree[l].cnt;
  tree[n].left += tree[r].left;
  tree[n].right += tree[l].right;
  if (tree[l].left >= tree[r].right) {
    tree[n].left += (tree[l].left - tree[r].right);
  } else {
    tree[n].right += (tree[r].right - tree[l].left);
  }
}
struct node query(int n, int b, int e, int i, int j) {
  if (i > e || j < b) {
    struct node c;
    c.left = c.right = c.cnt = 0;
    return c;
  } else if (i <= b && j >= e) {
    return tree[n];
  }
  int mid = (b + e) >> 1;
  int ll = n << 1;
  int rr = ll + 1;
  struct node l = query(ll, b, mid, i, j);
  struct node r = query(rr, mid + 1, e, i, j);
  struct node n1;
  n1.cnt = 2 * (min(r.right, l.left)) + r.cnt + l.cnt;
  n1.left += r.left;
  n1.right += l.right;
  if (l.left >= r.right) {
    n1.left += (l.left - r.right);
  } else {
    n1.right += (r.right - l.left);
  }
  return n1;
}
int main() {
  cin >> s;
  int l = s.length();
  init(1, 0, l - 1);
  int n;
  cin >> n;
  while (n--) {
    int a, b;
    cin >> a >> b;
    struct node c = query(1, 0, l - 1, a - 1, b - 1);
    cout << c.cnt << endl;
  }
  return 0;
}
