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>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const double PI = 3.141592653589793238463;
const int INF = 0x3f3f3f3f;
const int INFS = 1000000000;
const long long LLINF = 9223372036854775807;
const int M = 1000000007;
const int HM = 2147483647;
const int HP = 43;
const double EPS = 1e-8;
struct node {
  long long l, r, open, close, len;
  node *ln, *rn;
};
string s;
node* build(long long l, long long r) {
  if (l > r) return nullptr;
  node* res = new node;
  res->l = l;
  res->r = r;
  if (l == r) {
    res->open = 0;
    res->close = 0;
    if (s[l] == '(')
      res->open = 1;
    else
      res->close = 1;
    res->len = 0;
    res->ln = nullptr;
    res->rn = nullptr;
    return res;
  }
  long long mid = (l + r) / 2;
  res->ln = build(l, mid);
  res->rn = build(mid + 1, r);
  res->len =
      res->ln->len + res->rn->len + 2 * min(res->ln->open, res->rn->close);
  res->close =
      res->ln->close + res->rn->close - min(res->ln->open, res->rn->close);
  res->open =
      res->ln->open + res->rn->open - min(res->ln->open, res->rn->close);
  return res;
}
pair<long long, pair<long long, long long> > get(node* curr, long long l,
                                                 long long r) {
  if (curr->l > r || curr->r < l) return {0, {0, 0}};
  if (curr->l >= l && curr->r <= r)
    return {curr->len, {curr->close, curr->open}};
  pair<long long, pair<long long, long long> > lst = get(curr->ln, l, r),
                                               rst = get(curr->rn, l, r);
  return {lst.first + rst.first + 2 * min(lst.second.second, rst.second.first),
          {lst.second.first + rst.second.first -
               min(lst.second.second, rst.second.first),
           lst.second.second + rst.second.second -
               min(lst.second.second, rst.second.first)}};
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s;
  long long q, n = s.size();
  cin >> q;
  node* root = build(0, n - 1);
  while (q--) {
    long long l, r;
    cin >> l >> r;
    cout << get(root, l - 1, r - 1).first << endl;
  }
  return 0;
}
