#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 20;
int n;
char s[MAXN];
struct Range {
  int a, b, c;
};
Range merge(Range a, Range b) {
  int t = min(a.b, b.c);
  return {a.a + b.a + t, a.b + b.b - t, a.c + b.c - t};
}
class ST {
  struct Node {
    int l, r;
    Range n;
  };
  Node t[MAXN * 4];

 public:
  void build(int, int, int);
  Range max_subseq(int, int, int);
};
void ST::build(int u, int l, int r) {
  (t[u]).l = l;
  (t[u]).r = r;
  if (l == r) {
    (t[u]).n = {0, s[l] == '(' ? 1 : 0, s[l] == ')' ? 1 : 0};
    return;
  }
  int mid = (l + r) / 2;
  build((u * 2), l, mid);
  build((u * 2 + 1), mid + 1, r);
  (t[u]).n = merge((t[(u * 2)]).n, (t[(u * 2 + 1)]).n);
}
Range ST::max_subseq(int u, int l, int r) {
  if (l <= (t[u]).l && (t[u]).r <= r) return (t[u]).n;
  int mid = ((t[u]).l + (t[u]).r) / 2;
  Range ans = {0, 0, 0};
  if (mid >= l) ans = merge(ans, max_subseq((u * 2), l, r));
  if (mid < r) ans = merge(ans, max_subseq((u * 2 + 1), l, r));
  return ans;
}
int main() {
  static ST t;
  scanf("%s", s + 1);
  n = strlen(s + 1);
  t.build(1, 1, n);
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", t.max_subseq(1, l, r).a * 2);
  }
}
