#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 20;
struct qtype {
  int match;
  int left, right;
  qtype() { match = left = right = 0; }
  qtype(int a, int b, int c) {
    match = a;
    left = b;
    right = c;
  }
  qtype operator+(const qtype& q) const {
    int m = min(left, q.right);
    return qtype(match + q.match + m, left + q.left - m, right + q.right - m);
  }
} tree[2 * MAXN];
int Q;
qtype query(int a, int b, int cur = 1, int l = 0, int r = MAXN) {
  if (a <= l && r <= b) {
    return tree[cur];
  }
  if (r <= a || b <= l) return qtype();
  int mid = (l + r) / 2;
  return query(a, b, 2 * cur, l, mid) + query(a, b, 2 * cur + 1, mid, r);
}
int main() {
  if (fopen("codeforces381E.in", "r")) freopen("codeforces381E.in", "r", stdin);
  char c;
  for (int i = 0; scanf("%c", &c) && c != '\n'; i++) {
    qtype& ref = tree[i + MAXN];
    (c == '(' ? ref.left : ref.right) = 1;
  }
  for (int i = MAXN - 1; i; i--) tree[i] = tree[2 * i] + tree[2 * i + 1];
  scanf("%d", &Q);
  while (Q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", query(l - 1, r).match << 1);
  }
  return 0;
}
