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;
int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
class debug_t {
 public:
  template <typename T>
  debug_t &operator<<(const T &o) {
    return *this;
  }
  void end() {
    *this << "\nExecution Time = " << clock() * 1.0 / CLOCKS_PER_SEC << '\n';
    exit(0);
  }
} dout;
struct Node {
  int a, b;
  Node() : a(0), b(0) {}
  Node(int a, int b) : a(a), b(b) {}
  Node(char c) {
    a = c == '(' ? 1 : -1;
    b = 0;
  }
  int size() const { return abs(a) + abs(b); }
};
ostream &operator<<(ostream &out, Node &n) {
  out << '(' << n.a << "," << n.b << ')';
  return out;
}
Node operator+(Node A, Node B) {
  if (!A.a && !A.b) return B;
  if (!B.a && !B.b) return A;
  if (A.b == 0) swap(A.a, A.b);
  if (B.a == 0) swap(B.a, B.b);
  int a = A.a, b = A.b, c = B.a, d = B.b;
  if (!a && b < 0 && c < 0 && !d) return Node(b + c, 0);
  if (!a && b < 0 && c > 0 && !d) return Node(b, c);
  if (!a && b < 0 && c < 0 && d > 0) return Node(b + c, d);
  if (!a && b > 0 && c < 0 && !d) return Node(b + c, 0);
  if (!a && b > 0 && c > 0 && !d) return Node(b + c, 0);
  if (!a && b > 0 && c < 0 && d > 0) {
    Node ret(b + c, d);
    if (ret.a > 0) ret.a += ret.b, ret.b = 0;
    return ret;
  }
  if (a < 0 && b > 0 && c < 0 && !d) {
    Node ret(a, b + c);
    if (ret.a < 0 && ret.b < 0 || ret.a > 0 && ret.b > 0)
      ret.a += ret.b, ret.b = 0;
    return ret;
  }
  if (a < 0 && b > 0 && c > 0 && !d) return Node(a, b + c);
  if (a < 0 && b > 0 && c < 0 && d > 0) {
    int mid = b + c;
    return mid > 0 ? Node(a, mid + d) : Node(a + mid, d);
  }
}
Node tree[2 * 2000006];
char s[2000006];
int n;
void build(int st = 0, int en = n - 1, int node = 1) {
  if (st == en) {
    tree[node] = Node(s[st]);
    return;
  }
  int mid = (st + en) / 2;
  build(st, mid, 2 * node);
  build(mid + 1, en, 2 * node + 1);
  tree[node] = tree[2 * node] + tree[2 * node + 1];
}
Node query(int a, int b, int st = 0, int en = n - 1, int node = 1) {
  if (st > b || en < a) return Node();
  if (a <= st && en <= b) {
    return tree[node];
  }
  int mid = (st + en) / 2;
  auto ret =
      query(a, b, st, mid, 2 * node) + query(a, b, mid + 1, en, 2 * node + 1);
  return ret;
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  int m;
  scanf("%d", &m);
  build();
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    printf("%d\n", (b - a + 1 - query(a, b).size()));
  }
  dout.end();
}
