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>
const int NN = 1000000 + 10;
char ch[NN];
int N, Q;
int a[NN << 2], b[NN << 2], c[NN << 2];
int MIN(int a, int b) { return a < b ? a : b; }
void PushUp(int idx) {
  int ls = idx << 1, rs = idx << 1 | 1;
  int t = MIN(b[ls], c[rs]);
  a[idx] = a[ls] + a[rs] + (t << 1);
  b[idx] = b[rs] + b[ls] - t;
  c[idx] = c[ls] + c[rs] - t;
}
void build(int l, int r, int idx) {
  int mid = (l + r) >> 1;
  if (l == r) {
    if (ch[l] == '(') {
      a[idx] = 0;
      b[idx] = 1;
      c[idx] = 0;
    } else {
      a[idx] = 0;
      b[idx] = 0;
      c[idx] = 1;
    }
    return;
  }
  build(l, mid, idx << 1);
  build(mid + 1, r, idx << 1 | 1);
  PushUp(idx);
}
int query(int l, int r, int idx, int a1, int b1, int& ltemp, int& rtemp) {
  if (l == a1 && r == b1) {
    ltemp = b[idx];
    rtemp = c[idx];
    return a[idx];
  }
  int mid = (l + r) >> 1;
  if (b1 <= mid)
    return query(l, mid, idx << 1, a1, b1, ltemp, rtemp);
  else if (mid < a1)
    return query(mid + 1, r, idx << 1 | 1, a1, b1, ltemp, rtemp);
  else {
    int temp1, temp2;
    int sum1 = query(l, mid, idx << 1, a1, mid, ltemp, temp1);
    int sum2 = query(mid + 1, r, idx << 1 | 1, mid + 1, b1, temp2, rtemp);
    int tt = MIN(ltemp, rtemp);
    ltemp = temp2 + ltemp - tt;
    rtemp = temp1 + rtemp - tt;
    return sum1 + sum2 + tt * 2;
  }
}
int main() {
  scanf("%s", ch);
  N = strlen(ch);
  build(0, N - 1, 1);
  scanf("%d", &Q);
  int l, r, ltemp, rtemp;
  while (Q--) {
    scanf("%d%d", &l, &r);
    l--;
    r--;
    printf("%d\n", query(0, N - 1, 1, l, r, ltemp, rtemp));
  }
  return 0;
}
