#include <bits/stdc++.h>
using namespace std;
int T[2234567], A[2234567], B[2234567];
string s;
void build(int v, int tl, int tr) {
  if (tl == tr) {
    if (s[tl] == '(') {
      A[v] = 1;
    } else {
      B[v] = 1;
    }
    return;
  }
  int tm = (tl + tr) / 2;
  build(2 * v, tl, tm);
  build(2 * v + 1, tm + 1, tr);
  int tmp = min(A[2 * v], B[2 * v + 1]);
  T[v] = (T[2 * v] + T[2 * v + 1] + 2 * tmp);
  A[v] = (A[2 * v] + A[2 * v + 1] - tmp);
  B[v] = (B[2 * v] + B[2 * v + 1] - tmp);
}
pair<int, pair<int, int> > answer(int v, int tl, int tr, int l, int r) {
  if (l > tr || r < tl) {
    return pair<int, pair<int, int> >(0, pair<int, int>(0, 0));
  }
  if (l <= tl && r >= tr) {
    return pair<int, pair<int, int> >(T[v], pair<int, int>(A[v], B[v]));
  }
  int tm = (tl + tr) / 2;
  pair<int, pair<int, int> > fa = answer(2 * v, tl, tm, l, r);
  pair<int, pair<int, int> > sa = answer(2 * v + 1, tm + 1, tr, l, r);
  int tmp = min(fa.second.first, sa.second.second);
  int tre = fa.first + sa.first + 2 * tmp;
  int a = fa.second.first + sa.second.first - tmp;
  int b = fa.second.second + sa.second.second - tmp;
  return pair<int, pair<int, int> >(tre, pair<int, int>(a, b));
}
int l, r, m;
int main() {
  cin >> s;
  build(1, 0, s.size() - 1);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    l--;
    r--;
    printf("%d\n", answer(1, 0, s.size() - 1, l, r).first);
  }
  return 0;
}
