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 segment {
  int res;
  int close;
  int open;
  segment() { res = close = open = 0; }
} tree[3 * 1000000 + 10];
void make_tree(int node, int left, int right) {
  if (left >= right) {
    tree[node].res = 0;
    if (s[left] == ')') {
      tree[node].open = 0;
      tree[node].close = 1;
    } else {
      tree[node].open = 1;
      tree[node].close = 0;
    }
    return;
  }
  int l = node * 2;
  int r = node * 2 + 1;
  int mid = (left + right) / 2;
  make_tree(l, left, mid);
  make_tree(r, mid + 1, right);
  tree[node].res = tree[l].res + tree[r].res;
  int mn = min(tree[l].open, tree[r].close);
  tree[node].res += mn * 2;
  tree[node].close = tree[l].close + tree[r].close - mn;
  tree[node].open = tree[r].open + tree[l].open - mn;
}
segment query(int node, int left, int right, int x, int y) {
  if (left > y || right < x) {
    segment p;
    return p;
  }
  if (left >= x && right <= y) return tree[node];
  int mid = (left + right) / 2;
  segment l = query(node * 2, left, mid, x, y);
  segment r = query((node * 2) + 1, mid + 1, right, x, y);
  segment p;
  p.res = l.res + r.res;
  int mn = min(l.open, r.close);
  p.res += mn * 2;
  p.close = l.close + r.close - mn;
  p.open = r.open + l.open - mn;
  return p;
}
int main() {
  string p = "s";
  cin >> s;
  int len = s.size();
  s = p + s;
  make_tree(1, 1, len);
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    segment p = query(1, 1, len, x, y);
    printf("%d\n", p.res);
  }
  return 0;
}
