#include <bits/stdc++.h>
struct node {
  node() { zuo = you = he = 0; }
  int zuo, you, he;
} a[1000002];
char s[1000002];
int sum(int l, int r) {
  int ans = 0, you = 0;
  while (r >= l) {
    while (r && r - l + 1 >= (r & -r)) {
      ans += a[r].he;
      if (a[r].zuo >= you) {
        ans += you;
        you = 0;
      } else {
        ans += a[r].zuo;
        you -= a[r].zuo;
      }
      you += a[r].you;
      r -= r & -r;
    }
    if (r >= l) {
      if (s[r] == '(') {
        if (you) {
          ++ans;
          --you;
        }
      } else
        ++you;
      --r;
    }
  }
  return ans;
}
int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1), x;
  for (int i = 1; i <= n; ++i) {
    x = i;
    if (s[x] == '(') {
      while (x <= n) {
        ++a[x].zuo;
        x += x & -x;
      }
    } else {
      while (x <= n) {
        if (a[x].zuo) {
          --a[x].zuo;
          ++a[x].he;
        } else
          ++a[x].you;
        x += x & -x;
      }
    }
  }
  int m, l, r;
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &l, &r);
    printf("%d\n", sum(l, r) << 1);
  }
  return 0;
}
