#include <bits/stdc++.h>
using namespace std;
const int N = 1001000;
struct Tree {
  int l, r, ls, rs, s;
  Tree(int l = 0, int r = 0, int ls = 0, int rs = 0, int s = 0)
      : l(l), r(r), ls(ls), rs(rs), s(s) {}
  Tree operator+(const Tree &x) const {
    return Tree(l, x.r, ls + x.ls, rs + x.rs,
                s + x.s + min(ls - s, x.rs - x.s));
  }
} a[N * 3];
int l, r, m;
char s[N];
void build(int o) {
  if (a[o].l == a[o].r) {
    if (s[a[o].l - 1] == '(')
      a[o].ls++;
    else
      a[o].rs++;
  } else {
    int lc = 2 * o, rc = 2 * o + 1;
    a[lc] = Tree(a[o].l, (a[o].l + a[o].r) >> 1);
    a[rc] = Tree(a[lc].r + 1, a[o].r);
    build(lc);
    build(rc);
    a[o] = a[lc] + a[rc];
  }
}
Tree get(int o, int l, int r) {
  if ((l <= a[o].l) && (a[o].r <= r))
    return a[o];
  else {
    int lc = 2 * o, rc = 2 * o + 1;
    Tree L, R;
    if (l <= a[lc].r) L = get(lc, l, r);
    if (a[rc].l <= r) R = get(rc, l, r);
    return L + R;
  }
}
int main() {
  scanf("%s", s);
  a[1].l = 1;
  a[1].r = strlen(s);
  build(1);
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &l, &r);
    Tree ans = get(1, l, r);
    printf("%d\n", 2 * ans.s);
  }
  return 0;
}
