#include <bits/stdc++.h>
using namespace std;
pair<long long, pair<long long, long long> > stree[4000005];
string sa;
void build(long long node, long long start, long long end) {
  if (start == end) {
    if (sa[start] == '(')
      stree[node] = make_pair(0, make_pair(1, 0));
    else
      stree[node] = make_pair(0, make_pair(0, 1));
  } else {
    long long mid = (start + end) / 2;
    build(2 * node + 1, start, mid);
    build(2 * node + 2, mid + 1, end);
    long long temp = min(stree[2 * node + 1].second.first,
                         stree[2 * node + 2].second.second);
    long long total =
        stree[2 * node + 1].first + stree[2 * node + 2].first + temp;
    long long x = stree[2 * node + 1].second.first +
                  stree[2 * node + 2].second.first - temp;
    long long y = stree[2 * node + 1].second.second +
                  stree[2 * node + 2].second.second - temp;
    stree[node] = make_pair(total, make_pair(x, y));
  }
}
pair<long long, pair<long long, long long> > query(long long node,
                                                   long long start,
                                                   long long end, long long l,
                                                   long long r) {
  if (l > end || start > r) return make_pair(0, make_pair(0, 0));
  if (l <= start && end <= r) return stree[node];
  long long mid = (start + end) / 2;
  pair<long long, pair<long long, long long> > p1 =
      query(2 * node + 1, start, mid, l, r);
  pair<long long, pair<long long, long long> > p2 =
      query(2 * node + 2, mid + 1, end, l, r);
  long long temp = min(p1.second.first, p2.second.second);
  long long total = p1.first + p2.first + temp;
  long long x = p1.second.first + p2.second.first - temp;
  long long y = p1.second.second + p2.second.second - temp;
  return make_pair(total, make_pair(x, y));
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  cin >> sa;
  long long n = sa.length();
  build(0, 0, n - 1);
  long long q;
  cin >> q;
  while (q-- != 0) {
    long long l, r;
    cin >> l >> r;
    l--;
    r--;
    cout << 2 * query(0, 0, n - 1, l, r).first << endl;
  }
  return 0;
}
