#include <bits/stdc++.h>
using namespace std;
int mx[4000050];
int op[4000050];
int cl[4000050];
int n;
string s;
void build(int in, int l, int r) {
  if (l == r) {
    if (s[l - 1] == '(') {
      mx[in] = 0;
      op[in] = 1;
      cl[in] = 0;
    } else {
      mx[in] = 0;
      op[in] = 0;
      cl[in] = 1;
    }
    return;
  }
  int mid = (l + r) / 2;
  build(2 * in, l, mid);
  build(2 * in + 1, mid + 1, r);
  int x = min(op[2 * in], cl[2 * in + 1]);
  mx[in] = mx[2 * in] + mx[2 * in + 1] + x * 2;
  op[in] = op[2 * in] + op[2 * in + 1] - x;
  cl[in] = cl[2 * in] + cl[2 * in + 1] - x;
}
pair<int, pair<int, int> > query(int in, int l, int r, int lt, int rt) {
  if (l > rt || r < lt)
    return pair<int, pair<int, int> >(0, pair<int, int>(0, 0));
  if (l == lt && r == rt) {
    return pair<int, pair<int, int> >(mx[in], pair<int, int>(op[in], cl[in]));
  }
  int mid = (lt + rt) / 2;
  if (l > mid)
    return query(2 * in + 1, l, r, mid + 1, rt);
  else if (r <= mid)
    return query(2 * in, l, r, lt, mid);
  else {
    pair<int, pair<int, int> > p, q, t;
    p = query(2 * in, l, mid, lt, mid);
    q = query(2 * in + 1, mid + 1, r, mid + 1, rt);
    int x = min(p.second.first, q.second.second);
    t.first = p.first + q.first + x * 2;
    t.second.first = p.second.first + q.second.first - x;
    t.second.second = p.second.second + q.second.second - x;
    return t;
  }
}
int main() {
  cin >> s;
  n = s.size();
  build(1, 1, n);
  int i, j;
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << query(1, l, r, 1, n).first << endl;
  }
  return 0;
}
