#include <bits/stdc++.h>
char str[1000005];
typedef struct node {
  int l, r;
  int haspp;
  int lb, rb;
};
int Min(int aa, int bb) { return aa < bb ? aa : bb; }
node Tr[1000005 * 4];
void buildTr(int left, int right, int k) {
  if (left == right) {
    Tr[k].l = Tr[k].r = left;
    Tr[k].haspp = 0;
    if (str[left] == '(') {
      Tr[k].lb = 1;
      Tr[k].rb = 0;
    } else {
      Tr[k].lb = 0;
      Tr[k].rb = 1;
    }
    return;
  }
  Tr[k].l = left;
  Tr[k].r = right;
  int Mid = (left + right) >> 1;
  buildTr(left, Mid, 2 * k);
  buildTr(Mid + 1, right, 2 * k + 1);
  int ans1 = Min(Tr[2 * k].lb, Tr[2 * k + 1].rb);
  Tr[k].haspp = ans1 + Tr[2 * k].haspp + Tr[2 * k + 1].haspp;
  Tr[k].lb = Tr[2 * k].lb - ans1 + Tr[2 * k + 1].lb;
  Tr[k].rb = Tr[2 * k].rb + Tr[2 * k + 1].rb - ans1;
}
node search(int L, int R, int k) {
  if (Tr[k].l == L && Tr[k].r == R) {
    return Tr[k];
  }
  if (Tr[k].l == Tr[k].r) return Tr[k];
  int Mid = (Tr[k].l + Tr[k].r) >> 1;
  if (Mid < L) {
    return search(L, R, 2 * k + 1);
  } else if (R <= Mid) {
    return search(L, R, 2 * k);
  } else {
    node ans1 = search(L, Mid, 2 * k);
    node ans2 = search(Mid + 1, R, 2 * k + 1);
    node ans;
    ans.haspp = ans1.haspp + ans2.haspp;
    int tmp = Min(ans1.lb, ans2.rb);
    ans.haspp = ans.haspp + tmp;
    ans.lb = ans1.lb - tmp + ans2.lb;
    ans.rb = ans2.rb - tmp + ans1.rb;
    return ans;
  }
}
void solve(int m) {
  int L, R;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &L, &R);
    int ans = search(L, R, 1).haspp;
    printf("%d\n", ans * 2);
  }
}
int main() {
  int m, n;
  while (scanf("%s", str + 1) != EOF) {
    n = strlen(str + 1);
    buildTr(1, n, 1);
    scanf("%d", &m);
    solve(m);
  }
  return 0;
}
