#include <bits/stdc++.h>
using namespace std;
struct data {
  int res, one, zero;
};
data seg[4 * 1000000 + 10];
string s;
void insert(int indx, int st, int ed, int val, int pos) {
  if (st == ed) {
    if (val == 1) {
      seg[indx].one = 1;
      seg[indx].zero = 0;
    } else {
      seg[indx].one = 0;
      seg[indx].zero = 1;
    }
    seg[indx].res = 0;
    return;
  }
  int mid = (st + ed) / 2, L = indx * 2 + 1, R = indx * 2 + 2;
  if (pos <= mid)
    insert(L, st, mid, val, pos);
  else
    insert(R, mid + 1, ed, val, pos);
  int tmp = min(seg[L].one, seg[R].zero);
  seg[indx].res = seg[L].res + seg[R].res + tmp;
  seg[indx].one = seg[L].one - tmp + seg[R].one;
  seg[indx].zero = seg[L].zero + seg[R].zero - tmp;
}
data query(int indx, int st, int ed, int from, int to) {
  if (st == from && ed == to) return seg[indx];
  int mid = (st + ed) / 2, L = indx * 2 + 1, R = indx * 2 + 2;
  if (to <= mid)
    return query(L, st, mid, from, to);
  else if (from > mid)
    return query(R, mid + 1, ed, from, to);
  else {
    data X = query(L, st, mid, from, mid);
    data Y = query(R, mid + 1, ed, mid + 1, to);
    data tmp;
    int com = min(X.one, Y.zero);
    tmp.res = X.res + Y.res + com;
    tmp.one = X.one - com + Y.one;
    tmp.zero = X.zero + Y.zero - com;
    return tmp;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cin >> s;
  int len = s.length();
  for (int i = 0; i < len; i++) {
    if (s[i] == '(')
      insert(0, 0, len - 1, 1, i);
    else
      insert(0, 0, len - 1, 0, i);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    data get = query(0, 0, len - 1, l, r);
    cout << 2 * get.res << endl;
  }
  return 0;
}
