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 MinIndex {
  int32_t min;
  uint32_t from_index;
  uint32_t to_index;
  MinIndex() : min(INT32_MAX) {}
  MinIndex(int32_t val, uint32_t index)
      : min(val), from_index(index), to_index(index) {}
  MinIndex(int32_t val, uint32_t from_index, uint32_t to_index)
      : min(val), from_index(from_index), to_index(to_index) {}
};
const MinIndex operator+(const MinIndex &val1, const MinIndex &val2) {
  if (val1.min == val2.min) {
    return MinIndex(val1.min, std::min(val1.from_index, val2.from_index),
                    std::max(val1.to_index, val2.to_index));
  } else if (val1.min < val2.min) {
    return MinIndex(val1.min, val1.from_index, val1.to_index);
  } else {
    return MinIndex(val2.min, val2.from_index, val2.to_index);
  }
}
template <class T>
class RMQ {
  uint32_t MAX_ITEMS;
  vector<T> rmq_array;
  uint32_t binary_ceiling(uint32_t v) {
    v--;
    v |= v >> 1;
    v |= v >> 2;
    v |= v >> 4;
    v |= v >> 8;
    v |= v >> 16;
    v++;
    return v;
  }
  const T better_query(uint32_t l, uint32_t r) {
    uint32_t level_start = MAX_ITEMS;
    T sum;
    do {
      if (l & 1) {
        sum = sum + rmq_array[level_start + l - 1];
      }
      if (r & 1) {
        sum = sum + rmq_array[level_start + r - 2];
      }
      l = (l + 1) >> 1;
      r >>= 1;
      level_start >>= 1;
    } while (l < r);
    return sum;
  }

 public:
  RMQ(uint32_t max_items) {
    MAX_ITEMS = binary_ceiling(max_items);
    if (max_items == MAX_ITEMS) MAX_ITEMS <<= 1;
    rmq_array.resize(2 * MAX_ITEMS);
  }
  void build(vector<T> initial) {
    uint32_t level_start = MAX_ITEMS;
    auto target = rmq_array.begin();
    advance(target, level_start - 1);
    copy(initial.begin(), initial.end(), target);
    do {
      auto prev_level_start = level_start;
      level_start >>= 1;
      for (int i = 0; i < level_start; i++) {
        rmq_array[level_start + i - 1] =
            rmq_array[prev_level_start + (2 * i) - 1] +
            rmq_array[prev_level_start + (2 * i)];
      }
    } while (level_start);
  }
  void update(uint32_t idx, T t) {
    uint32_t index = idx;
    uint32_t level_start = MAX_ITEMS;
    while (level_start) {
      rmq_array[level_start + index - 1] =
          rmq_array[level_start + index - 1] + t;
      index >>= 1;
      level_start >>= 1;
    }
  }
  const T query(uint32_t l, uint32_t r) { return better_query(l, r); }
  const T operator[](uint32_t index) {
    return rmq_array[MAX_ITEMS + index - 1];
  }
};
int main() {
  ios::sync_with_stdio(0);
  int IO_BUFFER_SIZE = 4096;
  char rd_io_buffer[IO_BUFFER_SIZE];
  char wr_io_buffer[IO_BUFFER_SIZE];
  cin.rdbuf()->pubsetbuf(rd_io_buffer, IO_BUFFER_SIZE);
  vector<MinIndex> temp;
  temp.push_back(MinIndex(0, 0));
  temp.reserve(IO_BUFFER_SIZE);
  uint32_t index = 1;
  int32_t height = 0;
  char c;
  cin >> c;
  do {
    if (c == '(')
      height++;
    else
      height--;
    temp.push_back(MinIndex(height, index));
    index++;
  } while ((c = cin.get()) != '\n');
  RMQ<MinIndex> brackets(temp.size());
  brackets.build(temp);
  int32_t n;
  cin >> n;
  vector<int> result_list;
  result_list.reserve(n);
  for (int32_t i = 0; i < n; i++) {
    uint32_t l, r;
    cin >> l >> r;
    const MinIndex min_indexes = brackets.query(l - 1, r + 1);
    int32_t middle = min_indexes.to_index - min_indexes.from_index;
    uint32_t left_width = min_indexes.from_index - l + 1;
    int left_height = abs(brackets[l - 1].min - min_indexes.min);
    uint32_t right_width = r - min_indexes.to_index;
    int right_height = abs(brackets[r].min - min_indexes.min);
    int32_t result =
        middle + (left_width - left_height) + (right_width - right_height);
    result_list.push_back(result);
  }
  for (auto result : result_list) {
    cout << result << '\n';
  }
}
