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 = (int)1e9 + 7;
const long double PI = acos((long double)-1);
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
string s;
struct Segment_Tree {
  int op, cl, res;
} st[1000010 * 4], fk[1000010 * 4];
int n, k, m, ls, rs;
void Built_smt(int l, int r, int v) {
  if (l == r) {
    if (s[l] == '(')
      st[v].op = 1;
    else
      st[v].cl = 1;
    return;
  }
  int mid = (l + r + 1) / 2;
  Built_smt(l, mid - 1, v * 2);
  Built_smt(mid, r, v * 2 + 1);
  st[v].res =
      st[v * 2].res + st[v * 2 + 1].res + min(st[v * 2].op, st[v * 2 + 1].cl);
  st[v].op =
      st[v * 2 + 1].op + st[v * 2].op - min(st[v * 2].op, st[v * 2 + 1].cl);
  st[v].cl =
      st[v * 2].cl + st[v * 2 + 1].cl - min(st[v * 2].op, st[v * 2 + 1].cl);
}
int Get(int l, int r, int v) {
  if (l > rs || r < ls) {
    fk[v].cl = fk[v].op = 0;
    return 0;
  }
  if (l >= ls && r <= rs) {
    fk[v].cl = st[v].cl;
    fk[v].op = st[v].op;
    return st[v].res;
  }
  int mid = (l + r + 1) / 2;
  fk[v].res = Get(l, mid - 1, v * 2) + Get(mid, r, v * 2 + 1) +
              min(fk[v * 2].op, fk[v * 2 + 1].cl);
  fk[v].op =
      fk[v * 2 + 1].op + fk[v * 2].op - min(fk[v * 2].op, fk[v * 2 + 1].cl);
  fk[v].cl =
      fk[v * 2].cl + fk[v * 2 + 1].cl - min(fk[v * 2].op, fk[v * 2 + 1].cl);
  return fk[v].res;
}
inline void Init() {
  cin >> s;
  n = int((s).size());
  s = " " + s;
  Built_smt(1, n, 1);
}
inline void Solve() {
  int q;
  cin >> q;
  while (q--) {
    cin >> ls >> rs;
    cout << Get(1, n, 1) * 2 << endl;
  }
}
int main(int argc, char** argv) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Init();
  Solve();
  return 0;
}
