#include <bits/stdc++.h>
using namespace std;
const int N = 4000001;
const int oo = -1;
int lb[N];
int rb[N];
int vs[N];
char s[N];
int n;
void update(int lq, int rq, char v, int li, int ri, int c) {
  if (rq < li || ri < lq) return;
  if (lq <= li && ri <= rq) {
    if (v == '(')
      lb[c] = 1;
    else
      rb[c] = 1;
    return;
  }
  int m = li + (ri - li) / 2;
  update(lq, rq, v, li, m, 2 * c);
  update(lq, rq, v, m + 1, ri, 2 * c + 1);
  vs[c] = vs[2 * c] + vs[2 * c + 1] + min(lb[2 * c], rb[2 * c + 1]);
  lb[c] = lb[2 * c + 1];
  rb[c] = rb[2 * c];
  if (lb[2 * c] < rb[2 * c + 1])
    rb[c] += rb[2 * c + 1] - lb[2 * c];
  else
    lb[c] += lb[2 * c] - rb[2 * c + 1];
}
pair<int, pair<int, int>> query(int lq, int rq, int li, int ri, int c) {
  if (rq < li || ri < lq) return make_pair(oo, make_pair(oo, oo));
  if (lq <= li && ri <= rq) {
    return make_pair(vs[c], make_pair(lb[c], rb[c]));
  }
  int m = li + (ri - li) / 2;
  pair<int, pair<int, int>> op1 = query(lq, rq, li, m, 2 * c);
  pair<int, pair<int, int>> op2 = query(lq, rq, m + 1, ri, 2 * c + 1);
  if (op1.first == oo) return op2;
  if (op2.first == oo) return op1;
  int aa = op1.first + op2.first;
  int bb = op1.second.first + op2.second.first;
  int cc = op1.second.second + op2.second.second;
  if (op1.second.first < op2.second.second) {
    aa += op1.second.first;
    bb -= op1.second.first;
    cc -= op1.second.first;
  } else {
    aa += op2.second.second;
    bb -= op2.second.second;
    cc -= op2.second.second;
  }
  return make_pair(aa, make_pair(bb, cc));
}
int main() {
  fill(lb, lb + N, 0);
  fill(rb, rb + N, 0);
  fill(vs, vs + N, 0);
  int Q;
  scanf("%s %d", s, &Q);
  n = strlen(s);
  for (int i = 0; i < n; i++) {
    update(i, i, s[i], 0, n - 1, 1);
  }
  for (int i = 0; i < Q; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    l--;
    r--;
    printf("%d\n", 2 * query(l, r, 0, n - 1, 1).first);
  }
  return 0;
}
