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;
vector<int> baz;
int a[1000000 + 10];
struct node {
  int first, last, l, r;
  vector<int> val;
  node() {
    first = -1;
    last = -1;
    l = -1;
    r = -1;
    val.clear();
  }
};
vector<node> v;
void add(int i) {
  if (v[i].first == v[i].last) {
    return;
  }
  node l, r;
  int mid = (v[i].first + v[i].last) / 2;
  l.first = v[i].first;
  l.last = mid;
  r.first = mid + 1;
  r.last = v[i].last;
  v.push_back(l);
  v[i].l = v.size() - 1;
  v.push_back(r);
  v[i].r = v.size() - 1;
  add(v[i].l);
  add(v[i].r);
}
void F(int i, int val) {
  if (v[i].first > val || v[i].last < val) {
    return;
  }
  v[i].val.push_back(a[val]);
  if (v[i].l != -1) {
    F(v[i].l, val);
    F(v[i].r, val);
  }
}
int ans = 0;
void G(int i, int lef, int ri, int kaf) {
  if (v[i].first > ri || v[i].last < lef) {
    return;
  }
  if (v[i].first < lef || v[i].last > ri) {
    G(v[i].l, lef, ri, kaf);
    G(v[i].r, lef, ri, kaf);
  } else {
    int f, s;
    f = 0;
    s = v[i].val.size() - 1;
    if (v[i].val.size()) {
      if (v[i].val[0] >= kaf) {
        ans += v[i].val.size();
      } else {
        if (v[i].val[v[i].val.size() - 1] < kaf) {
          ans += 0;
        } else {
          while (1) {
            if (f == s) {
              if (v[i].val[f] < kaf) {
                ans += (v[i].val.size() - 1) - f;
              } else {
                ans += (v[i].val.size() - 1) - f;
                ans++;
              }
              break;
            }
            int m = (f + s) / 2;
            if (v[i].val[m] >= kaf) {
              s = m;
            } else {
              f = m + 1;
            }
          }
        }
      }
    }
  }
}
int main() {
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '(') {
      baz.push_back(i + 1);
    } else {
      if (baz.size() > 0) {
        a[i + 1] = baz[baz.size() - 1];
        baz.pop_back();
      }
    }
  }
  node f;
  f.first = 1;
  f.last = n;
  v.push_back(f);
  add(0);
  for (int i = 1; i <= n; i++)
    if (a[i] != 0) {
      F(0, i);
    }
  for (int i = 0; i < v.size(); i++) {
    sort(v[i].val.begin(), v[i].val.end());
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int left, right;
    cin >> left >> right;
    G(0, left, right, left);
    cout << "	" << ans * 2 << endl;
    ans = 0;
  }
}
