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 long long N = 2e6 + 5;
const long long INF = 1e18L;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
long long ar[N];
long long dp[N];
struct segment {
  long long len, o, c;
  string brac;
  segment() {
    len = 0;
    o = 0;
    c = 0;
  }
} seg[N];
string str;
void build(long long l, long long r, long long tn) {
  if (l > r) return;
  if (l == r) {
    if (l == str.size()) return;
    if (str[l] == ')')
      seg[tn].c++, seg[tn].brac += ')';
    else
      seg[tn].o++, seg[tn].brac += '(';
    return;
  }
  long long mid = (l + r) / 2;
  build(l, mid, 2 * tn + 1);
  build(mid + 1, r, 2 * tn + 2);
  long long x = min(seg[2 * tn + 1].o, seg[2 * tn + 2].c);
  seg[tn].o = seg[2 * tn + 1].o + seg[2 * tn + 2].o - x;
  seg[tn].c = seg[2 * tn + 1].c + seg[2 * tn + 2].c - x;
  seg[tn].brac = seg[2 * tn + 1].brac + seg[2 * tn + 2].brac;
  seg[tn].len = seg[2 * tn + 1].len + seg[2 * tn + 2].len + x;
}
tuple<long long, long long, long long> Merge(
    tuple<long long, long long, long long>& a,
    tuple<long long, long long, long long>& b) {
  tuple<long long, long long, long long> z;
  long long x = min(get<0>(a), get<1>(b));
  get<0>(z) = get<0>(a) + get<0>(b) - x;
  get<1>(z) = get<1>(a) + get<1>(b) - x;
  get<2>(z) = get<2>(a) + get<2>(b) + x;
  return z;
}
tuple<long long, long long, long long> query(long long ql, long long qr,
                                             long long l, long long r,
                                             long long tn) {
  if (ql > r || qr < l)
    return make_tuple(0, 0, 0);
  else if (ql <= l && qr >= r) {
    return make_tuple(seg[tn].o, seg[tn].c, seg[tn].len);
  }
  long long mid = (l + r) >> 1ll;
  tuple<long long, long long, long long> a, b;
  a = query(ql, qr, l, mid, 2 * tn + 1);
  b = query(ql, qr, mid + 1, r, 2 * tn + 2);
  return Merge(a, b);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long T = 1;
  while (T--) {
    cin >> str;
    long long q;
    cin >> q;
    long long n = str.size();
    build(0, n, 0);
    while (q--) {
      long long l, r;
      cin >> l >> r;
      --l;
      --r;
      tuple<long long, long long, long long> ans;
      ans = query(l, r, 0, n, 0);
      cout << 2 * get<2>(ans) << endl;
    }
  }
  cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
  return 0;
}
