#include <bits/stdc++.h>
using namespace std;
long long n;
void buildtree(long long tree[][3], string &second, long long index,
               long long start, long long end) {
  if (start > end) return;
  if (start == end) {
    if (second[start] == '(')
      tree[index][0]++;
    else
      tree[index][1]++;
    return;
  }
  long long mid = (start + end) / 2;
  buildtree(tree, second, 2 * index, start, mid);
  buildtree(tree, second, 2 * index + 1, mid + 1, end);
  long long y = min(tree[2 * index][0], tree[2 * index + 1][1]);
  tree[index][0] = (tree[2 * index][0] + tree[2 * index + 1][0] - y);
  tree[index][1] = (tree[2 * index][1] + tree[2 * index + 1][1] - y);
  tree[index][2] = (tree[2 * index][2] + tree[2 * index + 1][2] + y);
  return;
}
tuple<long long, long long, long long> query(long long tree[][3],
                                             long long index, long long second,
                                             long long e, long long qs,
                                             long long qe) {
  if (qs > e || second > qe)
    return make_tuple((long long)0, (long long)0, (long long)0);
  if (qe >= e && second >= qs) {
    return make_tuple(tree[index][0], tree[index][1], tree[index][2]);
  }
  long long mid = (second + e) / 2;
  tuple<long long, long long, long long> left =
      query(tree, 2 * index, second, mid, qs, qe);
  tuple<long long, long long, long long> right =
      query(tree, 2 * index + 1, mid + 1, e, qs, qe);
  long long x1 = get<0>(left);
  long long x2 = get<1>(left);
  long long x3 = get<2>(left);
  long long y1 = get<0>(right);
  long long y2 = get<1>(right);
  long long y3 = get<2>(right);
  long long t = min(x1, y2);
  long long a1 = x1 + y1 - t;
  long long b1 = x2 + y2 - t;
  long long c1 = x3 + y3 + t;
  return make_tuple(a1, b1, c1);
}
void solve() {
  string second;
  cin >> second;
  n = second.size();
  long long tree[4 * n + 1][3];
  memset(tree, 0, sizeof(tree));
  buildtree(tree, second, 1, 0, n - 1);
  long long q;
  cin >> q;
  while (q--) {
    long long x, y;
    cin >> x >> y;
    x--, y--;
    tuple<long long, long long, long long> ans = query(tree, 1, 0, n - 1, x, y);
    cout << 2 * (get<2>(ans)) << "\n";
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t;
  t = 1;
  while (t--) solve();
  return 0;
}
