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;
const double EPS = 1e-9;
const double PI = 3.14159265359;
vector<long long> primes;
void GeneratingPrimes(int top) {
  vector<bool> p(top + 1, 1);
  p[0] = p[1] = 0;
  for (int i = 2; i <= sqrt(top); i++) {
    if (p[i]) {
      for (int j = i * i; j <= top; j += i) {
        p[j] = 0;
      }
    }
  }
  for (int i = 0; i < top + 1; i++)
    if (p[i]) primes.push_back(i);
}
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
void EXTgcd(long long a, long long b, long long& x0, long long& y0) {
  if (b == 0) {
    x0 = 1, y0 = 0;
    return;
  }
  EXTgcd(b, a % b, x0, y0);
  long long x1 = y0;
  long long y1 = x0 - (a / b) * (y0);
  y1 = y1;
  x0 = x1;
  y0 = y1;
}
long long power(long long n, long long p, long long mod) {
  if (!p) return 1;
  long long ans = 1;
  while (p > 1) {
    if (p & 1) ans = (ans * n) % mod;
    n = (n * n) % mod;
    p /= 2;
  }
  return (ans * n) % mod;
}
double dist(double a, double b, double x, double y) {
  return sqrt(pow(a - x, 2) + pow(b - y, 2));
}
double dist3(double a, double b, double c, double x, double y, double z) {
  return sqrt(pow(a - x, 2) + pow(b - y, 2) + pow(c - z, 2));
}
int xadd[9] = {1, -1, 0, 1, -1, 0, 1, -1, 0};
int yadd[9] = {1, -1, 0, -1, 0, 1, 0, 1, -1};
int xx[4] = {0, 1, 0, -1};
int yy[4] = {1, 0, -1, 0};
long long const N = 1e6 + 10;
long long const INF = 1e18;
long long const mod = 1000000009;
vector<int> segTree[4 * N];
int n, q, myR[N];
string s;
void mergeTrees(vector<int>& l, vector<int>& r, vector<int>& to) {
  int i = 0, j = 0;
  while (i < l.size() && j < r.size()) {
    if (l[i] <= r[j])
      to.push_back(l[i++]);
    else
      to.push_back(r[j++]);
  }
  while (i < l.size()) to.push_back(l[i++]);
  while (j < r.size()) to.push_back(r[j++]);
}
void buildTree(int idx, int l, int r) {
  if (l == r) {
    segTree[idx].push_back(myR[l]);
    return;
  }
  int mid = (l + r) >> 1;
  buildTree(idx * 2 + 1, l, mid);
  buildTree(idx * 2 + 2, mid + 1, r);
  mergeTrees(segTree[idx * 2 + 1], segTree[idx * 2 + 2], segTree[idx]);
}
int query(int idx, int tl, int tr, int l, int r) {
  if ((tr < l) || (tl > r)) {
    return 0;
  }
  if ((l <= tl) && (tr <= r)) {
    int cur = upper_bound(segTree[idx].begin(), segTree[idx].end(), r) -
              segTree[idx].begin();
    return cur;
  }
  int mid = (tl + tr) >> 1, cur = 0;
  cur = query(idx * 2 + 1, tl, mid, l, r);
  cur += query(idx * 2 + 2, mid + 1, tr, l, r);
  return cur;
}
void getCouples() {
  stack<int> st;
  for (int i = 0; i < n; i++) {
    if (s[i] == '(') {
      st.push(i);
    } else {
      if (st.size()) {
        int x = st.top();
        st.pop();
        myR[x] = i;
      }
    }
  }
}
int main() {
  cin >> s;
  n = s.size();
  for (int i = 0; i < N; i++) myR[i] = N;
  getCouples();
  buildTree(0, 0, n - 1);
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    int cur = query(0, 0, n - 1, x, y);
    printf("%d\n", cur * 2);
  }
  return 0;
}
