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;
struct Node {
  int x, y, z;
};
Node tree[3000009];
string str;
void build(int l, int r, int v) {
  if (l == r) {
    if (str[l] == '(') {
      tree[v].x = 0;
      tree[v].y = 1;
      tree[v].z = 0;
    } else {
      tree[v].x = 0;
      tree[v].y = 0;
      tree[v].z = 1;
    }
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, 2 * v);
  build(mid + 1, r, 2 * v + 1);
  int temp = min(tree[2 * v].y, tree[2 * v + 1].z);
  tree[v].x = tree[v * 2].x + tree[2 * v + 1].x + temp;
  tree[v].y = tree[v * 2].y + tree[v * 2 + 1].y - temp;
  tree[v].z = tree[v * 2].z + tree[v * 2 + 1].z - temp;
}
Node find(int l, int r, int x1, int y1, int v) {
  if (l == x1 && r == y1) {
    return tree[v];
  }
  int mid = (l + r) / 2;
  if (y1 <= mid)
    return find(l, mid, x1, y1, 2 * v);
  else if (x1 > mid)
    return find(mid + 1, r, x1, y1, 2 * v + 1);
  else {
    Node temp1 = find(l, mid, x1, mid, 2 * v);
    Node temp2 = find(mid + 1, r, mid + 1, y1, 2 * v + 1);
    int temp = min(temp1.y, temp2.z);
    Node temp3;
    temp3.x = temp1.x + temp2.x + temp;
    temp3.y = temp1.y + temp2.y - temp;
    temp3.z = temp1.z + temp2.z - temp;
    return temp3;
  }
}
int main() {
  cin >> str;
  build(0, str.size() - 1, 1);
  int q;
  cin >> q;
  while (q--) {
    int g, h;
    cin >> g >> h;
    cout << 2 * find(0, str.size() - 1, g - 1, h - 1, 1).x << endl;
  }
}
