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;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int mx = 1e6 + 5;
const int INF = 1000000007;
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y >>= 1;
    x = (x * x) % 1000000007;
  }
  return (res % 1000000007);
}
string str;
struct node {
  int pair, open, closed;
  node() { pair = open = closed = 0; }
};
vector<node> tree(4 * mx);
void build_tree(long long si, long long ss, long long se) {
  if (ss == se) {
    tree[si].pair = 0;
    tree[si].open = (str[ss] == '(');
    tree[si].closed = (str[ss] == ')');
    return;
  }
  long long mid = (ss + se) / 2;
  build_tree(2 * si, ss, mid);
  build_tree(2 * si + 1, mid + 1, se);
  int x = min(tree[2 * si].open, tree[2 * si + 1].closed);
  tree[si].pair = tree[2 * si].pair + tree[2 * si + 1].pair + x;
  tree[si].open = tree[2 * si].open + tree[2 * si + 1].open - x;
  tree[si].closed = tree[2 * si].closed + tree[2 * si + 1].closed - x;
}
node query(long long si, long long ss, long long se, long long qs,
           long long qe) {
  if (ss > qe || se < qs) {
    node temp;
    return temp;
  }
  if (ss >= qs && se <= qe) {
    return tree[si];
  }
  long long mid = (ss + se) / 2;
  node left = query(2 * si, ss, mid, qs, qe);
  node right = query(2 * si + 1, mid + 1, se, qs, qe);
  node curr;
  int x = min(left.open, right.closed);
  curr.pair = left.pair + right.pair + x;
  curr.open = left.open + right.open - x;
  curr.closed = left.closed + right.closed - x;
  return curr;
}
void solve() {
  str += '0';
  string ref;
  cin >> ref;
  str += ref;
  int n = ref.size();
  build_tree(1, 1, n);
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    cout << query(1, 1, n, a, b).pair * 2 << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
}
