#include <bits/stdc++.h>
using namespace std;
char s[1000100];
struct node {
  int f, s, b;
} Tree[4000100];
int q, a, b, n;
void build(int cn, int st, int ed) {
  if (st == ed) {
    Tree[cn].b = 0;
    if (s[st] == '(')
      Tree[cn].f = 1;
    else
      Tree[cn].s = 1;
    return;
  }
  int lft = cn << 1, rgt = lft + 1, mid = (st + ed) / 2;
  build(lft, st, mid);
  build(rgt, mid + 1, ed);
  int mn = min(Tree[lft].f, Tree[rgt].s);
  Tree[cn].b = Tree[lft].b + Tree[rgt].b + (mn << 1);
  Tree[cn].f = Tree[lft].f + Tree[rgt].f - mn;
  Tree[cn].s = Tree[lft].s + Tree[rgt].s - mn;
}
node query(int cn, int st, int ed, int L, int R) {
  if (st == L && ed == R) return Tree[cn];
  int lft = cn << 1, rgt = lft + 1, mid = (st + ed) / 2;
  if (R <= mid)
    return query(lft, st, mid, L, R);
  else if (L > mid)
    return query(rgt, mid + 1, ed, L, R);
  else {
    node tmpa = query(lft, st, mid, L, mid);
    node tmpb = query(rgt, mid + 1, ed, mid + 1, R);
    node tmp;
    int mn = min(tmpa.f, tmpb.s);
    tmp.b = tmpa.b + tmpb.b + (mn << 1);
    tmp.f = tmpa.f + tmpb.f - mn;
    tmp.s = tmpa.s + tmpb.s - mn;
    return tmp;
  }
}
int main() {
  memset(Tree, 0, sizeof Tree);
  scanf("%s", s + 1);
  n = strlen(s + 1);
  build(1, 1, n);
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &a, &b);
    printf("%d\n", query(1, 1, n, a, b).b);
  }
}
