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 bData {
  int openLeft, value, openRight;
  bData() : openLeft(0), value(0), openRight(0) {}
  bData(int l, int v, int r) : openLeft(l), value(v), openRight(r) {}
};
int log(int x) {
  int output = 0;
  while (x > 1) {
    output++;
    x /= 2;
  }
  return output;
}
int max(int x, int y) { return x > y ? x : y; }
bData merge(bData bd1, bData bd2) {
  int dValue = min(bd1.openLeft, bd2.openRight);
  int value = bd1.value + bd2.value + 2 * dValue;
  return bData((bd1.openLeft - dValue) + bd2.openLeft, value,
               bd1.openRight + (bd2.openRight - dValue));
}
bData merge(bData bd1, bData bd2, bData bd3) {
  return merge(merge(bd1, bd2), bd3);
}
bData mergeAll(bData** data, int n, int start, int end) {
  if (end <= start) {
    return bData(0, 0, 0);
  } else if (end - start == 1) {
    return data[0][start];
  } else {
    int logn = log(n);
    int level = logn;
    int p = 1 << logn;
    while (p >= 1) {
      if (end / p > start / p) {
        if (start % p == 0) {
          return merge(data[level][start / p],
                       mergeAll(data, n, start + p, end));
        } else if (((start / p) + 1) * p + p <= end) {
          return merge(mergeAll(data, n, start, (start / p + 1) * p),
                       data[level][start / p + 1],
                       mergeAll(data, n, ((start / p) + 1) * p + p, end));
        } else {
          p /= 2;
          level--;
        }
      } else {
        p /= 2;
        level--;
      }
    }
    return bData(0, 0, 0);
  }
}
int main() {
  string str;
  cin >> str;
  const char* cstr = str.c_str();
  int n = str.length();
  int m;
  cin >> m;
  int l, r;
  int lg = log(n) + 1;
  bData** data = new bData*[lg];
  for (int i = 0, p = 1; i < lg; i++, p *= 2) {
    data[i] = new bData[n / p + 1];
    for (int j = 0, start = 0, end = p - 1; end < n;
         start += p, end = min(start + p - 1, n), j++) {
      if (i == 0) {
        data[0][j] = cstr[start] == '(' ? bData(1, 0, 0) : bData(0, 0, 1);
      } else {
        data[i][j] = merge(data[i - 1][2 * j], data[i - 1][2 * j + 1]);
      }
    }
  }
  for (int t = 0; t < m; t++) {
    cin >> l;
    l--;
    cin >> r;
    r--;
    cout << mergeAll(data, n, l, r + 1).value << endl;
  }
}
